3

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.

tomasyany
  • 1,132
  • 3
  • 15
  • 32
  • See also http://stackoverflow.com/questions/4348733/saving-interactive-matplotlib-figures That question is 3.5 years old, but as far as I know, such capability still does not exist in mpl. Using pickle sounds like a reasonable alternative. –  Jun 13 '14 at 09:28
  • Closing as duplicate. If someone thinks things have changed in the last 3.5 years or has a better shot, answering there is a good idea. It gets a fair few more views than this. – Veedrac Jun 13 '14 at 09:33
  • I just read that question, but it is true it is quite old now. I have search a lot on the internet and Matplotlib doc to see if there's a way, but nothing yet it seems. The thing is that dumping the info and then loading it again is slow when you want to share your plot with someone else, or simply see it again without having to manipulate the data again (loading, putting into the plot, etc can be tedious, specially when your code evolves through time). – tomasyany Jun 13 '14 at 09:33
  • The current way of sharing figures with other people seems to be using the IPython notebook: you save all the commands you used to create a figure and either send the corresponding JSON file, or point them to a webpage which shows the commands (which, presumably, also uses that JSON file to recreate your IPython notebook). The web interface doesn't allow interactive plot fiddling yet, so for that, use the saved session of IPython command line version. –  Jun 13 '14 at 09:38

0 Answers0