Page13/13
Advanced Styling & Publication-Ready Plots Β· Page 1 of 1
Professional Plot Styling
Advanced Styling & Publication-Ready Plots
Using Style Sheets
Matplotlib comes with predefined styles:
plt.style.use('seaborn-v0_8-darkgrid') # Modern Seaborn style
plt.style.use('ggplot') # R ggplot2 style
Available styles: `['seaborn-v0_8', 'default', 'dark_background', 'bmh', 'fivethirtyeight', 'ggplot', ...]
Figure and Axes Properties
fig, ax = plt.subplots(figsize=(12, 7))
# DPI (dots per inch) β higher = sharper
fig.savefig('plot.png', dpi=300)
# Spine removal (for cleaner look)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
# Custom grid
ax.grid(True, alpha=0.3, linestyle='--', linewidth=0.5)
Advanced Legend Options
ax.legend(loc='best', framealpha=0.9, fontsize=11,
title='Variables', title_fontsize=12,
ncol=2) # 2 columns
Annotations
Add text, arrows, and highlights:
ax.annotate('Important Point!',
xy=(x_val, y_val), # point to mark
xytext=(x_text, y_text), # where to put text
arrowprops=dict(arrowstyle='->', color='red'),
fontsize=11, ha='left')
Font Management
import matplotlib.font_manager as fm
# Set global font
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.size'] = 11
plt.rcParams['axes.titlesize'] = 14
Publication tip: Save as PDF or EPS for papers, PNG/JPEG for web. Use 300 DPI for printing.
main.py
Loading...
OUTPUT
βΆClick "Run Code" to executeβ¦