I am generating several plots with matplotlib.pyplot as plt
from a Python script, and saving them into .png
. I have a list of figures in self.figures
of an user defined object called myPlotter
, and I do the following:
# Saving figures
def savePlots(self):
i = 0
for fig in self.figures:
fig.savefig('plots/myPlot'+str(i)+'.png')
i += 1
When I do so, I lose all possible information that I could have if I would have shown the plot with plt.show()
. For example, if I had an x
axis with a lot of values that because of the size of the figure cannot be seen all at the same time, I could zoom it in the Matplolib GUI and see the detail of this axis, that will change with every zoom. But when I save the plot, I just get (as one can expect) a raster image where I have lost this faculty to zoom, to see details, etc.
I was then wondering if there is a way to save a plot in such a way that I can open it later with the GUI and get all the information that was originally in the plot.
What I have done so far is to save the data with the pickle
package (through pickle.dump
) and then restore it with pickle.load
, and plot again. But I would love, if it ever exists, a faster way of doing so.