Skip to content Skip to sidebar Skip to footer

Save Figure Parameters After Interactive Tweaking

I often find myself using matplotlib to quickly display data, then later going back and tweaking my plotting code to make pretty figures. In this process, I often use the interacti

Solution 1:

While I don't have the answer to your specific question, I'd generally suggest using the Ipython Notebook for these things (and much more!)

Make sure you have %pylab inline in one cell.

When you plot, it will display it in the notebook itself. Then within your cell, just keep experimenting until you have it right (use Ctrl-Enter in the cell). Now the cell will have all the statements you need (and no more!)

The difference between the command line interpreter and the notebook is that the former all statements you typed which leads to a lot of clutter. With the notebook you can edit the line in place.


Solution 2:

A similar question here has an answer I just posted here.

The gist: use MatPlotLib's picklable figure object to save the figure object to a file. See the aforementioned answer for a full example. Here's a shortened example:

fig, ax = matplotlib.pyplot.subplots()
# plot some stuff

import pickle
pickle.dump(  fig,  open('SaveToFile.pickle',  'wb')  )

This does indeed save all plotting tweaks, even those made by the GUI subplot-adjuster. Unpickling via pickle.load() still allows you to interact via CLI or GUI.


Post a Comment for "Save Figure Parameters After Interactive Tweaking"