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?
The new default colormap used by matplotlib. cm. ScalarMappable instances is 'viridis' (aka option D).
By default, the size of the Matplotlib plots is 6 x 4 inches. The default size of the plots can be checked using this command: import matplotlib.pyplot as plt print(plt.rcParams.get('figure.figsize'))
Changing the Defaults: rcParams Each time Matplotlib loads, it defines a runtime configuration (rc) containing the default styles for every plot element you create. This configuration can be adjusted at any time using the plt.
There are three ways to customize Matplotlib: Setting rcParams at runtime. Using style sheets. Changing your matplotlibrc file.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With