I do much (practically all) of my data analysis in Jupyter/iPython-notebooks. For convenience, I obviously also plot my data in those notebooks using matplotlib
/pyplot
.
Some of those plots I need to recreate externally later on, for example to use them in latex
. For this I save the corresponding data as textfiles to the harddrive. Right now, I manually create a numpy-array by stacking all the data needed for the plot, and save this using numpy.savetxt
.
What I would like to have is a way to save all data needed for a specific plot written to the same file in an (semi)automatic way, but I am at a loss if it comes to the smart way of doing so.
Thus I have two questions:
Is it possible (and save to do) to create something like a plot-memory object, that stores all data plotted per figure, and has a method similar to
Memoryobject.save_plot_to_file(figname)
? This object would need to know which figure I am working on, so I would need to create a layer above matplotlib, or get this information from the matplotlib objectsIs there a simpler way? The python universe is huge, and I do not know half of it. Maybe something like this already exists?
Edit: Clarification: I do not want to save the figure object. What I want to do is something like this:
fig = plt.figure()
fig.plot(x1, y1)
fig.plot(x2, y2 + y3)
# and at a later point
arrays = get_data_from_plot(fig)
data = process(arrays)
np.savetxt('textfile', data)