matplotlib默认参数

🔖 python
🔖 visualization
Author

Guangyao Zhao

Published

Oct 10, 2022

在 matplotlib 中,运行如下代码即可获取全部可自定义参数:

import matplotlib as mpl

print(mpl.rc_params()) 

默认参数的设置格式如下:

import matplotlib as mpl

mpl.rcParams['figure.figsize'] = (8, 6) # 将画布大小设置为 8*6

一共有 304 个参数可设置:

#! figure
figure.dpi: 100.0
figure.edgecolor: white
figure.facecolor: white
figure.figsize: [6.4, 4.8]
figure.frameon: True
figure.raise_window: True
figure.titlesize: large
figure.titleweight: normal
# ===
figure.autolayout: False
figure.constrained_layout.h_pad: 0.04167
figure.constrained_layout.hspace: 0.02
figure.constrained_layout.use: False
figure.constrained_layout.w_pad: 0.04167
figure.constrained_layout.wspace: 0.02
figure.max_open_warning: 20
figure.subplot.bottom: 0.11
figure.subplot.hspace: 0.2
figure.subplot.left: 0.125
figure.subplot.right: 0.9
figure.subplot.top: 0.88
figure.subplot.wspace: 0.2


#! axes
axes.edgecolor: black
axes.facecolor: white
axes.grid: False
axes.grid.axis: both
axes.grid.which: major
axes.labelcolor: black
axes.labelpad: 4.0
axes.labelsize: medium
axes.labelweight: normal
axes.linewidth: 0.8
axes.spines.bottom: True
axes.spines.left: True
axes.spines.right: True
axes.spines.top: True
axes.titlecolor: auto
axes.titlelocation: center
axes.titlepad: 6.0
axes.titlesize: large
axes.titleweight: normal
axes.xmargin: 0.05
axes.ymargin: 0.05
axes.zmargin: 0.05
# ===
axes.autolimit_mode: data
axes.axisbelow: line
axes.formatter.limits: [-5, 6]
axes.formatter.min_exponent: 0
axes.formatter.offset_threshold: 4
axes.formatter.use_locale: False
axes.formatter.use_mathtext: False
axes.formatter.useoffset: True
axes.prop_cycle: cycler('color', ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'])
axes.titley: None
axes.unicode_minus: True
axes3d.grid: True

#! xaxis and xtick
xaxis.labellocation: center
xtick.alignment: center
xtick.bottom: True
xtick.color: black
xtick.direction: out
xtick.labelbottom: True
xtick.labelcolor: inherit
xtick.labelsize: medium
xtick.labeltop: False
xtick.major.bottom: True
xtick.major.pad: 3.5
xtick.major.size: 3.5
xtick.major.top: True
xtick.major.width: 0.8
xtick.minor.bottom: True
xtick.minor.pad: 3.4
xtick.minor.size: 2.0
xtick.minor.top: True
xtick.minor.visible: False
xtick.minor.width: 0.6
xtick.top: False

#! yaxis and ytick
yaxis.labellocation: center
ytick.alignment: center_baseline
ytick.color: black
ytick.direction: out
ytick.labelcolor: inherit
ytick.labelleft: True
ytick.labelright: False
ytick.labelsize: medium
ytick.left: True
ytick.major.left: True
ytick.major.pad: 3.5
ytick.major.right: True
ytick.major.size: 3.5
ytick.major.width: 0.8
ytick.minor.left: True
ytick.minor.pad: 3.4
ytick.minor.right: True
ytick.minor.size: 2.0
ytick.minor.visible: False
ytick.minor.width: 0.6
ytick.right: False

#! font
font.family: ['sans-serif']
font.sans-serif: ['DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', 'sans-serif']
font.serif: ['DejaVu Serif', 'Bitstream Vera Serif', 'Computer Modern Roman', 'New Century Schoolbook', 'Century Schoolbook L', 'Utopia', 'ITC Bookman', 'Bookman', 'Nimbus Roman No9 L', 'Times New Roman', 'Times', 'Palatino', 'Charter', 'serif']
font.monospace: ['DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Computer Modern Typewriter', 'Andale Mono', 'Nimbus Mono L', 'Courier New', 'Courier', 'Fixed', 'Terminal', 'monospace']
font.size: 10.0
font.style: normal
font.weight: normal
#===
font.cursive: ['Apple Chancery', 'Textile', 'Zapf Chancery', 'Sand', 'Script MT', 'Felipa', 'Comic Neue', 'Comic Sans MS', 'cursive']
font.fantasy: ['Chicago', 'Charcoal', 'Impact', 'Western', 'Humor Sans', 'xkcd', 'fantasy']
font.stretch: normal
font.variant: normal


#! grid
grid.alpha: 1.0
grid.color: #b0b0b0
grid.linestyle: -
grid.linewidth: 0.8


#! legend
legend.loc: best # 图例位置
legend.frameon: True # 显示边框
legend.framealpha: 0.8 # 边框透明度
legend.edgecolor: 0.8 # 边框颜色
legend.facecolor: inherit # 背景颜色
legend.title_fontsize: None # 图例标题的字体大小
legend.borderpad: 0.4 # 边框偏离
legend.columnspacing: 2.0 # 列间隔
legend.fontsize: medium # 图例字体大小
legend.labelcolor: None # 图例标签颜色
legend.labelspacing: 0.5 # 图例和标签间隔
legend.fancybox: True # 边框阴影
#===
legend.borderaxespad: 0.5
legend.handleheight: 0.7
legend.handlelength: 2.0
legend.handletextpad: 0.8
legend.markerscale: 1.0
legend.numpoints: 1
legend.scatterpoints: 1
legend.shadow: False


#! savefig
savefig.bbox: None
savefig.directory: ~
savefig.dpi: figure
savefig.edgecolor: auto
savefig.facecolor: auto
savefig.format: png
savefig.orientation: portrait
savefig.pad_inches: 0.1
savefig.transparent: False


#!================================================================

#! lines
lines.linestyle: - # 样式
lines.linewidth: 1.5 # 宽度
lines.color: C0 # 颜色
lines.dashdot_pattern: [6.4, 1.6, 1.0, 1.6] # dashdot 样式
lines.dashed_pattern: [3.7, 1.6] # dashed 样式
lines.dotted_pattern: [1.0, 1.65] # dotted 样式
lines.marker: None
lines.markersize: 6.0 # 线上样本点大小
lines.markeredgecolor: auto # 线上样本点边缘颜色
lines.markeredgewidth: 1.0 # 线上样本点边框宽度
lines.markerfacecolor: auto # 线上样本点背景色
lines.scale_dashes: True 
#===
lines.antialiased: True
lines.dash_capstyle: butt
lines.dash_joinstyle: round
lines.solid_capstyle: projecting
lines.solid_joinstyle: round

#! markers
markers.fillstyle: full

#! scatter
scatter.edgecolors: face
scatter.marker: o

#! contour
contour.corner_mask: True
contour.linewidth: None
contour.negative_linestyle: dashed

#! text
text.color: black # 字体颜色
text.usetex: False # 是否使用 latex
text.latex.preamble:  # 字体 latex 导言区
text.hinting: force_autohint # 字体微调
#===
text.antialiased: True
text.hinting_factor: 8
text.kerning_factor: 0


#! mathtext
mathtext.default: it # 默认字体样式
mathtext.fontset: dejavusans # 字体种类
mathtext.it: sans:italic
mathtext.rm: sans
mathtext.sf: sans
mathtext.tt: monospace
mathtext.bf: sans:bold # 粗体
mathtext.cal: cursive # 计算符号,草书
mathtext.fallback: cm


#! boxplot
boxplot.bootstrap: None
boxplot.boxprops.color: black
boxplot.boxprops.linestyle: -
boxplot.boxprops.linewidth: 1.0
boxplot.capprops.color: black
boxplot.capprops.linestyle: -
boxplot.capprops.linewidth: 1.0
boxplot.flierprops.color: black
boxplot.flierprops.linestyle: none
boxplot.flierprops.linewidth: 1.0
boxplot.flierprops.marker: o
boxplot.flierprops.markeredgecolor: black
boxplot.flierprops.markeredgewidth: 1.0
boxplot.flierprops.markerfacecolor: none
boxplot.flierprops.markersize: 6.0
boxplot.meanline: False
boxplot.meanprops.color: C2
boxplot.meanprops.linestyle: --
boxplot.meanprops.linewidth: 1.0
boxplot.meanprops.marker: ^
boxplot.meanprops.markeredgecolor: C2
boxplot.meanprops.markerfacecolor: C2
boxplot.meanprops.markersize: 6.0
boxplot.medianprops.color: C1
boxplot.medianprops.linestyle: -
boxplot.medianprops.linewidth: 1.0
boxplot.notch: False
boxplot.patchartist: False
boxplot.showbox: True
boxplot.showcaps: True
boxplot.showfliers: True
boxplot.showmeans: False
boxplot.vertical: True
boxplot.whiskerprops.color: black
boxplot.whiskerprops.linestyle: -
boxplot.whiskerprops.linewidth: 1.0
boxplot.whiskers: 1.5



#! ========================================== Other
_internal.classic_mode: False
agg.path.chunksize: 0
animation.bitrate: -1
animation.codec: h264
animation.convert_args: []
animation.convert_path: convert
animation.embed_limit: 20.0
animation.ffmpeg_args: []
animation.ffmpeg_path: ffmpeg
animation.frame_format: png
animation.html: none
animation.writer: ffmpeg
#! backend
backend: module://matplotlib_inline.backend_inline
backend_fallback: True
#! date
date.autoformatter.day: %Y-%m-%d
date.autoformatter.hour: %m-%d %H
date.autoformatter.microsecond: %M:%S.%f
date.autoformatter.minute: %d %H:%M
date.autoformatter.month: %Y-%m
date.autoformatter.second: %H:%M:%S
date.autoformatter.year: %Y
date.converter: auto
date.epoch: 1970-01-01T00:00:00
date.interval_multiples: True
#! 
docstring.hardcopy: False
#! 
errorbar.capsize: 0.0
#! hist
hist.bins: 10
#! image
image.aspect: equal
image.cmap: viridis
image.composite_image: True
image.interpolation: antialiased
image.lut: 256
image.origin: upper
image.resample: True
#! interactive
interactive: False
#! keymap
keymap.back: ['left', 'c', 'backspace', 'MouseButton.BACK']
keymap.copy: ['ctrl+c', 'cmd+c']
keymap.forward: ['right', 'v', 'MouseButton.FORWARD']
keymap.fullscreen: ['f', 'ctrl+f']
keymap.grid: ['g']
keymap.grid_minor: ['G']
keymap.help: ['f1']
keymap.home: ['h', 'r', 'home']
keymap.pan: ['p']
keymap.quit: ['ctrl+w', 'cmd+w', 'q']
keymap.quit_all: []
keymap.save: ['s', 'ctrl+s']
keymap.xscale: ['k', 'L']
keymap.yscale: ['l']
keymap.zoom: ['o']
#! polaraxes
polaraxes.grid: True
#! ps
ps.distiller.res: 6000
ps.fonttype: 3
ps.papersize: letter
ps.useafm: False
ps.usedistiller: None
#! svg
svg.fonttype: path
svg.hashsalt: None
svg.image_inline: True
#! timezone
timezone: UTC
tk.window_focus: False
#! toolbar
toolbar: toolbar2
#! webagg
webagg.address: 127.0.0.1
webagg.open_in_browser: True
webagg.port: 8988
webagg.port_retries: 50
#! hatch
hatch.color: black
hatch.linewidth: 1.0