为Matplotlib创建默认值集 [英] Creating sets of default values for Matplotlib

查看:101
本文介绍了为Matplotlib创建默认值集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常为自己的研究作图,所有的默认设置都可以,但是经常不得不切换到为演讲/演示设计的图。我手动将所有字体大小设置为更大一点以便于阅读:

I am frequently making plots for my own research and all of the default settings are fine, but often have to switch over to making plots designed for talks/presentations; I manually set all of the font sizes a bit bigger for easier reading:

plot(xdata, ydata)
xlabel("x-axis data", fontsize=20)
ax = gca()
for labeltick in ax.xaxis.get_majorticklabels() + ax.yaxis.get_majorticklabels():
        labeltick.set_fontsize(15)

等。

感谢文档和类似这一个这样的问题,我知道如何控制默认值启动matplotlib时绘制参数。我考虑过要写一些非常快速的东西(mpl_defaults.py):

Thanks to documentation and questions like this one I know how to control default plotting parameters when I start up matplotlib. I thought about writing something really quick (mpl_defaults.py):

import matplotlib as mpl
def plot_for_talks():
    mpl.rcParams['font.size'] = 20
    mpl.rcParams['figure.subplot.left'] = .2
    mpl.rcParams['figure.subplot.right'] = .8
    mpl.rcParams['figure.subplot.bottom'] = .2
    mpl.rcParams['figure.subplot.top'] = .8

然后我的绘图代码可能只包含

Then my plotting code could just include

import mpl_defaults
plot_for_talks()

我的问题:有没有更合适的方法做这个?

My question: is there a more appropriate way to do this? Maybe something already built in?

推荐答案

尝试一下:

import matplotlib as mpl    
mpl.rc('figure.subplot', left=.2, right=.8, bottom=.2, top=.8)

应该有一个 site-packages / matplotlib / mpl-data / matplotlibrc文件,如文档5.1中所述。

And there should be a "site-packages/matplotlib/mpl-data/matplotlibrc" file, described in doc 5.1.

使用mpl.matplotlib_fname()获取rc文件路径,并对其进行修改,以使设置永久不变。

Use mpl.matplotlib_fname() to get your rc file path, and modify it so the setting will be permanent.

这篇关于为Matplotlib创建默认值集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆