Question

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)

and so on.

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?

Was it helpful?

Solution

Try this:

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

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

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

OTHER TIPS

If you manage your separate presentation modes by directories, you can put a matplotlibrc file in each project directory, and matplotlib will use the one in the current directory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top