matplotlib---1.查看配置、修改配置、配置文件
分类:
Matplotlib
matplotlib配置信息是从配置文件中读取的。在配置文件中可以为matplotlib几乎所有的属性指定永久有效的默认值。
1.查看配置
1 2 | import matplotlib matplotlib.rcParams |
结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | RcParams({ '_internal.classic_mode' : False , 'agg.path.chunksize' : 0 , 'animation.avconv_args' : [], 'animation.avconv_path' : 'avconv' , '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.html_args' : [], 'animation.writer' : 'ffmpeg' , 'axes.autolimit_mode' : 'data' , 'axes.axisbelow' : True , 'axes.edgecolor' : '.15' , 'axes.facecolor' : 'white' , 'axes.formatter.limits' : [ - 7 , 7 ], '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.grid' : False , 'axes.grid.axis' : 'both' , 'axes.grid.which' : 'major' , 'axes.hold' : None , 'axes.labelcolor' : '.15' , 'axes.labelpad' : 4.0 , 'axes.labelsize' : 12.0 , 'axes.labelweight' : 'normal' , 'axes.linewidth' : 1.25 , 'axes.prop_cycle' : cycler( 'color' , [( 0.2980392156862745 , 0.4470588235294118 , 0.6901960784313725 ), ( 0.8666666666666667 , 0.5176470588235295 , 0.3215686274509804 ), ( 0.3333333333333333 , 0.6588235294117647 , 0.40784313725490196 ), ( 0.7686274509803922 , 0.3058823529411765 , 0.3215686274509804 ), ( 0.5058823529411764 , 0.4470588235294118 , 0.7019607843137254 ), ( 0.5764705882352941 , 0.47058823529411764 , 0.3764705882352941 ), ( 0.8549019607843137 , 0.5450980392156862 , 0.7647058823529411 ), ( 0.5490196078431373 , 0.5490196078431373 , 0.5490196078431373 ), ( 0.8 , 0.7254901960784313 , 0.4549019607843137 ), ( 0.39215686274509803 , 0.7098039215686275 , 0.803921568627451 )]), 'axes.spines.bottom' : True , 'axes.spines.left' : True , 'axes.spines.right' : True , 'axes.spines.top' : True , 'axes.titlepad' : 6.0 , 'axes.titlesize' : 12.0 , 'axes.titleweight' : 'normal' , 'axes.unicode_minus' : True , 'axes.xmargin' : 0.05 , 'axes.ymargin' : 0.05 , 'axes3d.grid' : True , 'backend' : 'module://ipykernel.pylab.backend_inline' , 'backend.qt4' : None , 'backend.qt5' : None , 'backend_fallback' : True , 'boxplot.bootstrap' : None , 'boxplot.boxprops.color' : 'k' , 'boxplot.boxprops.linestyle' : '-' , 'boxplot.boxprops.linewidth' : 1.0 , 'boxplot.capprops.color' : 'k' , 'boxplot.capprops.linestyle' : '-' , 'boxplot.capprops.linewidth' : 1.0 , 'boxplot.flierprops.color' : 'k' , 'boxplot.flierprops.linestyle' : 'none' , 'boxplot.flierprops.linewidth' : 1.0 , 'boxplot.flierprops.marker' : 'o' , 'boxplot.flierprops.markeredgecolor' : 'k' , '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' : 'k' , 'boxplot.whiskerprops.linestyle' : '-' , 'boxplot.whiskerprops.linewidth' : 1.0 , 'boxplot.whiskers' : 1.5 , 'contour.corner_mask' : True , 'contour.negative_linestyle' : 'dashed' , 'datapath' : 'c:\\users\\nxf\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\matplotlib\\mpl-data' , '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' , 'docstring.hardcopy' : False , 'errorbar.capsize' : 0.0 , 'examples.directory' : '', '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.dpi' : 72.0 , 'figure.edgecolor' : ( 1 , 1 , 1 , 0 ), 'figure.facecolor' : 'white' , 'figure.figsize' : [ 6.0 , 4.0 ], 'figure.frameon' : True , 'figure.max_open_warning' : 20 , 'figure.subplot.bottom' : 0.125 , '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 , 'figure.titlesize' : 'large' , 'figure.titleweight' : 'normal' , 'font.cursive' : [ 'Apple Chancery' , 'Textile' , 'Zapf Chancery' , 'Sand' , 'Script MT' , 'Felipa' , 'cursive' ], 'font.family' : [ 'sans-serif' ], 'font.fantasy' : [ 'Comic Sans MS' , 'Chicago' , 'Charcoal' , 'ImpactWestern' , 'Humor Sans' , 'xkcd' , 'fantasy' ], 'font.monospace' : [ 'DejaVu Sans Mono' , 'Bitstream Vera Sans Mono' , 'Computer Modern Typewriter' , 'Andale Mono' , 'Nimbus Mono L' , 'Courier New' , 'Courier' , 'Fixed' , 'Terminal' , 'monospace' ], 'font.sans-serif' : [ 'Arial' , 'DejaVu Sans' , 'Liberation Sans' , 'Bitstream Vera Sans' , '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.size' : 12.0 , 'font.stretch' : 'normal' , 'font.style' : 'normal' , 'font.variant' : 'normal' , 'font.weight' : 'normal' , 'grid.alpha' : 1.0 , 'grid.color' : '.8' , 'grid.linestyle' : '-' , 'grid.linewidth' : 1.0 , 'hatch.color' : 'k' , 'hatch.linewidth' : 1.0 , 'hist.bins' : 10 , 'image.aspect' : 'equal' , 'image.cmap' : 'rocket' , 'image.composite_image' : True , 'image.interpolation' : 'nearest' , 'image.lut' : 256 , 'image.origin' : 'upper' , 'image.resample' : True , 'interactive' : True , 'keymap.all_axes' : [ 'a' ], 'keymap.back' : [ 'left' , 'c' , 'backspace' ], 'keymap.forward' : [ 'right' , 'v' ], 'keymap.fullscreen' : [ 'f' , 'ctrl+f' ], 'keymap.grid' : [ 'g' ], 'keymap.grid_minor' : [ 'G' ], 'keymap.home' : [ 'h' , 'r' , 'home' ], 'keymap.pan' : [ 'p' ], 'keymap.quit' : [ 'ctrl+w' , 'cmd+w' , 'q' ], 'keymap.quit_all' : [ 'W' , 'cmd+W' , 'Q' ], 'keymap.save' : [ 's' , 'ctrl+s' ], 'keymap.xscale' : [ 'k' , 'L' ], 'keymap.yscale' : [ 'l' ], 'keymap.zoom' : [ 'o' ], 'legend.borderaxespad' : 0.5 , 'legend.borderpad' : 0.4 , 'legend.columnspacing' : 2.0 , 'legend.edgecolor' : '0.8' , 'legend.facecolor' : 'inherit' , 'legend.fancybox' : True , 'legend.fontsize' : 11.0 , 'legend.framealpha' : 0.8 , 'legend.frameon' : True , 'legend.handleheight' : 0.7 , 'legend.handlelength' : 2.0 , 'legend.handletextpad' : 0.8 , 'legend.labelspacing' : 0.5 , 'legend.loc' : 'best' , 'legend.markerscale' : 1.0 , 'legend.numpoints' : 1 , 'legend.scatterpoints' : 1 , 'legend.shadow' : False , 'lines.antialiased' : True , 'lines.color' : 'C0' , 'lines.dash_capstyle' : 'butt' , 'lines.dash_joinstyle' : 'round' , 'lines.dashdot_pattern' : [ 6.4 , 1.6 , 1.0 , 1.6 ], 'lines.dashed_pattern' : [ 3.7 , 1.6 ], 'lines.dotted_pattern' : [ 1.0 , 1.65 ], 'lines.linestyle' : '-' , 'lines.linewidth' : 5.0 , 'lines.marker' : 'None' , 'lines.markeredgewidth' : 1.0 , 'lines.markersize' : 6.0 , 'lines.scale_dashes' : True , 'lines.solid_capstyle' : 'round' , 'lines.solid_joinstyle' : 'round' , 'markers.fillstyle' : 'full' , 'mathtext.bf' : 'sans:bold' , 'mathtext.cal' : 'cursive' , 'mathtext.default' : 'it' , 'mathtext.fallback_to_cm' : True , 'mathtext.fontset' : 'dejavusans' , 'mathtext.it' : 'sans:italic' , 'mathtext.rm' : 'sans' , 'mathtext.sf' : 'sans' , 'mathtext.tt' : 'monospace' , 'patch.antialiased' : True , 'patch.edgecolor' : 'w' , 'patch.facecolor' : ( 0.2980392156862745 , 0.4470588235294118 , 0.6901960784313725 ), 'patch.force_edgecolor' : True , 'patch.linewidth' : 1.0 , 'path.effects' : [], 'path.simplify' : True , 'path.simplify_threshold' : 0.1111111111111111 , 'path.sketch' : None , 'path.snap' : True , 'pdf.compression' : 6 , 'pdf.fonttype' : 3 , 'pdf.inheritcolor' : False , 'pdf.use14corefonts' : False , 'pgf.debug' : False , 'pgf.preamble' : [], 'pgf.rcfonts' : True , 'pgf.texsystem' : 'xelatex' , 'polaraxes.grid' : True , 'ps.distiller.res' : 6000 , 'ps.fonttype' : 3 , 'ps.papersize' : 'letter' , 'ps.useafm' : False , 'ps.usedistiller' : False , 'savefig.bbox' : None , 'savefig.directory' : '~' , 'savefig.dpi' : 'figure' , 'savefig.edgecolor' : 'w' , 'savefig.facecolor' : 'w' , 'savefig.format' : 'png' , 'savefig.frameon' : True , 'savefig.jpeg_quality' : 95 , 'savefig.orientation' : 'portrait' , 'savefig.pad_inches' : 0.1 , 'savefig.transparent' : False , 'scatter.marker' : 'o' , 'svg.fonttype' : 'path' , 'svg.hashsalt' : None , 'svg.image_inline' : True , 'text.antialiased' : True , 'text.color' : '.15' , 'text.hinting' : 'auto' , 'text.hinting_factor' : 8 , 'text.latex.preamble' : [], 'text.latex.preview' : False , 'text.latex.unicode' : False , 'text.usetex' : False , 'timezone' : 'UTC' , 'tk.window_focus' : False , 'toolbar' : 'toolbar2' , 'verbose.fileo' : 'sys.stdout' , 'verbose.level' : 'silent' , 'webagg.address' : '127.0.0.1' , 'webagg.open_in_browser' : True , 'webagg.port' : 8988 , 'webagg.port_retries' : 50 , 'xtick.alignment' : 'center' , 'xtick.bottom' : True , 'xtick.color' : '.15' , 'xtick.direction' : 'out' , 'xtick.labelbottom' : True , 'xtick.labelsize' : 11.0 , 'xtick.labeltop' : False , 'xtick.major.bottom' : True , 'xtick.major.pad' : 3.5 , 'xtick.major.size' : 6.0 , 'xtick.major.top' : True , 'xtick.major.width' : 1.25 , 'xtick.minor.bottom' : True , 'xtick.minor.pad' : 3.4 , 'xtick.minor.size' : 4.0 , 'xtick.minor.top' : True , 'xtick.minor.visible' : False , 'xtick.minor.width' : 1.0 , 'xtick.top' : False , 'ytick.alignment' : 'center_baseline' , 'ytick.color' : '.15' , 'ytick.direction' : 'out' , 'ytick.labelleft' : True , 'ytick.labelright' : False , 'ytick.labelsize' : 11.0 , 'ytick.left' : True , 'ytick.major.left' : True , 'ytick.major.pad' : 3.5 , 'ytick.major.right' : True , 'ytick.major.size' : 6.0 , 'ytick.major.width' : 1.25 , 'ytick.minor.left' : True , 'ytick.minor.pad' : 3.4 , 'ytick.minor.right' : True , 'ytick.minor.size' : 4.0 , 'ytick.minor.visible' : False , 'ytick.minor.width' : 1.0 , 'ytick.right' : False }) |
2.修改配置
(1)可以通过 matplotlib.rcParams
字典修改所有已经加载的配置项
1 2 3 4 | mp.rcParams[ 'lines.color' ] # 'C0' mp.rcParams[ 'lines.color' ] = 'r' mp.rcParams[ 'lines.color' ] # 'r' |
(2)可以通过matplotlib.rc(*args,**kwargs)
来修改配置项,其中args
是你要修改的属性,kwargs
是属性的关键字属性
(3)可以调用matplotlib.rcdefaults()
将所有配置重置为标准设置。
1 2 3 4 5 6 7 8 9 10 11 12 13 | >>> help (mp.rcdefaults) Help on function rcdefaults in module matplotlib: rcdefaults() Restore the rc params from Matplotlib's internal defaults. See Also - - - - - - - - rc_file_defaults : Restore the rc params from the rc file originally loaded by Matplotlib. matplotlib.style.use : Use a specific style file . Call ``style.use( 'default' )`` to restore the default style. |
3.配置文件
如果不希望在每次代码开始时进行参数配置,则可以在项目中给出配置文件。配置文件有三个位置:
-
系统级配置文件:通常在python的
site-packages
目录下。每次重装matplotlib
之后该配置文件就会被覆盖。 -
用户级配置文件:通常在
$HOME
目录下。可以用matplotlib.get_configdir()
函数来查找当前用户的配置文件目录。可以通过MATPLOTLIBRC
修改它的位置。 - 当前工作目录:即项目的目录。在当前目录下,可以为目录所包含的当前项目给出配置文件,文件名为
matplotlibrc
。
优先级顺序是: 当前工作目录 > 用户级配置文件 > 系统级配置文件。查看当前使用的配置文件的路径为: matplotlib.matplotlib_fname()
函数。
配置文件的内容常见的有以下几种:
- axes:设置坐标轴边界和表面的颜色、坐标刻度值大小和网格的显示
- backend:设置目标输出TkAgg和GTKAgg
- figure:控制dpi、边界颜色、图像大小和子区(
subplot
)设置 - font:字体(
font family
)、字体大小和样式设置 - grid:设置网格颜色和线型
- legend:设置图例以及其中的文本显示
- line:设置线条(颜色、线型、宽度等)和标记
- patch: 填充2D空间的图形图像,如多边形和圆。控制线宽、颜色和抗锯齿设置等。
- savefig:对保存的图形进行单独设置。如渲染的文件背景为白色。
- text:设置字体颜色、文本解析(纯文本和latex标记)等。
- verbose:设置matplotlib执行期间的信息输出,如silent、helpful、debug和debug--annoying
- xticks和yticks:为x、y轴的主刻度和次刻度设置颜色、大小、方向以及标签大小
分类:
Matplotlib
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现