Initial commit
This commit is contained in:
63
A题/ZJ_v2/plot_style.py
Normal file
63
A题/ZJ_v2/plot_style.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
Plot styling for O-Prize grade figures
|
||||
Ensures consistent, publication-quality appearance across all figures
|
||||
"""
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib as mpl
|
||||
from matplotlib import rcParams
|
||||
|
||||
def set_oprice_style():
|
||||
"""Set global matplotlib style for O-Prize quality figures"""
|
||||
|
||||
rcParams['font.family'] = 'serif'
|
||||
rcParams['font.serif'] = ['Times New Roman', 'DejaVu Serif']
|
||||
rcParams['font.size'] = 10
|
||||
rcParams['axes.labelsize'] = 11
|
||||
rcParams['axes.titlesize'] = 12
|
||||
rcParams['xtick.labelsize'] = 9
|
||||
rcParams['ytick.labelsize'] = 9
|
||||
rcParams['legend.fontsize'] = 9
|
||||
rcParams['figure.titlesize'] = 13
|
||||
|
||||
# Line and marker settings
|
||||
rcParams['lines.linewidth'] = 1.5
|
||||
rcParams['lines.markersize'] = 4
|
||||
rcParams['axes.linewidth'] = 0.8
|
||||
rcParams['grid.linewidth'] = 0.5
|
||||
rcParams['grid.alpha'] = 0.3
|
||||
|
||||
# Use constrained layout
|
||||
rcParams['figure.constrained_layout.use'] = True
|
||||
|
||||
# Color cycle (professional color scheme)
|
||||
mpl.rcParams['axes.prop_cycle'] = mpl.cycler(
|
||||
color=['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728',
|
||||
'#9467bd', '#8c564b', '#e377c2', '#7f7f7f']
|
||||
)
|
||||
|
||||
def save_figure(fig, filepath_base, dpi=300):
|
||||
"""
|
||||
Save figure in both PDF and PNG formats
|
||||
|
||||
Args:
|
||||
fig: matplotlib figure object
|
||||
filepath_base: path without extension (e.g., 'figures/Fig01')
|
||||
dpi: resolution for PNG output
|
||||
"""
|
||||
fig.savefig(f"{filepath_base}.pdf", dpi=dpi, bbox_inches='tight')
|
||||
fig.savefig(f"{filepath_base}.png", dpi=dpi, bbox_inches='tight')
|
||||
|
||||
def get_color_palette():
|
||||
"""Return standard color palette for consistent coloring"""
|
||||
return {
|
||||
'primary': '#1f77b4',
|
||||
'secondary': '#ff7f0e',
|
||||
'success': '#2ca02c',
|
||||
'danger': '#d62728',
|
||||
'info': '#17a2b8',
|
||||
'warning': '#ffc107',
|
||||
'dark': '#343a40',
|
||||
'light': '#f8f9fa',
|
||||
'grid': '#cccccc'
|
||||
}
|
||||
Reference in New Issue
Block a user