[Matplotlib-users] Changing style after unpickle
Florian Lindner
mailinglists at xgm.de
Mon Jul 24 01:35:51 EDT 2017
Hello,
I can happily pickle plot objects:
ax = plt.subplot(111)
x = np.linspace(0, 10)
y = np.exp(x)
plt.plot(x, y)
pickle.dump(ax, open('myplot.pickle', 'wb'))
and unpickle them:
ax = pickle.load(open('myplot.pickle', 'rb'))
plt.savefig('pickerestore.pdf')
My main use case for that is (should be) changing the style of the plots after creation. I have an appropriate function:
def set_save_fig_params(fig_width_pt = 418.25555):
""" From: http://scipy-cookbook.readthedocs.io/items/Matplotlib_LaTeX_Examples.html """
matplotlib.style.use('seaborn')
inches_per_pt = 1.0 / 72.0 # Convert pt to inches
golden_mean = (math.sqrt(5)-1.0) / 2.0 # Aesthetic ratio
fig_width = fig_width_pt * inches_per_pt # width in inches
fig_height = fig_width * golden_mean # height in inches
fig_size = [fig_width, fig_height]
params = {'backend': 'pdf',
'axes.labelsize': 8,
'font.size': 10,
'legend.fontsize': 7,
'xtick.labelsize': 8,
'ytick.labelsize': 8,
'text.usetex': True,
'figure.figsize': fig_size,
"pgf.rcfonts" : False}
plt.rcParams.update(params)
However, calling this function after or before (or both) unpickling has no effect on the saved plot. The default style
is still used.
How can I change/update the style of unpickled objects?
Thanks,
Florian
More information about the Matplotlib-users
mailing list