Changing style after unpickle

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Changing style after unpickle

Florian Lindner

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'))

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: """'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}

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?

Matplotlib-users mailing list
[hidden email]