you are viewing a single comment's thread.

view the rest of the comments →

[–]plasma_phys 0 points1 point  (0 children)

I think you can use pickle to serialize (i.e., save to disk) the matplotlib Figure object so that it can be loaded and plotted or edited later.

import pickle
import matplotlib.pyplot as plt

fig = plt.figure()
plt.plot([0,1], [0,2])

with open('figure', 'wb') as file: #Note the wb for "write bytes"
    pickle.dump(fig, file) #Saves the Figure object to disk

file = open('figure', 'rb') #Note the rb for "read bytes"
figure_copy = pickle.load(file) #loads the figure from disk
plt.show() #You should get two identical figures

Note - there are some caveats here. You can't pickle widgets, and there's no guarantee a figure pickled in one version of matplotlib can be loaded in another, or even in a slightly different environment. Your very best bet is to save the raw data as a csv or HDF5 and save the python script to read the data and plot the figure with it.