6

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?

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I was hoping to stay away from a "permanent" solution like editing the matplotlibrc file since I frequently switch between "regular" and "presentation" modes. Any ideas on how to make that frequent switch easier?
@vgm64: Then your solution is good enough. mpl.rcdefaults() will restore the standard matplotlib default settings. So you can write all settings in file like mysettings.py. And you don't have to put the setting calls in a function, just write them in the top scope. When you want switch to "presentation" mode:"import mysettings", switch back:"mpl.rcdefaults()", "presentation" mode again: reload(mysettings)
4

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.