I want to save and edit plots generated by matplotlib (not image file, prefer editable file). I used the pickle package and I can save and open a plot by following code.
#-------------
#save code
#-------------
import matplotlib.pyplot as plt
import numpy as np
import pickle
fig = plt.figure('exp_plot')
ax = fig.add_subplot(111)
ax.set_xlim(0, 10)
ax.set_xlabel("x")
ax.set_ylabel("y")
x = np.linspace(0, 10)
y = np.exp(x)
ax.plot(x, y)
pickle.dump(ax, file('exp_plot.pickle', 'wb'))
#-------------
#load code
#-------------
import matplotlib.pyplot as plt
import pickle
fig = pickle.load(open('exp_plot.pickle', 'rb'))
plt.show()
However I can't edit the plot (e.g. change the x axis range, edit the plot title, change the line style) by "Figure options" window of the figure window. When I tried to change the x axis range on the window, the error messages were as follows.
Traceback (most recent call last):
File "C:\Anaconda2\lib\site-packages\matplotlib\backends\qt_editor\formlayout.py", line 472, in apply
self.apply_callback(self.formwidget.get())
File "C:\Anaconda2\lib\site-packages\matplotlib\backends\qt_editor\figureoptions.py", line 124, in apply_callback
axes.set_yscale(yscale)
File "C:\Anaconda2\lib\site-packages\matplotlib\axes\_base.py", line 3096, in set_yscale
self.autoscale_view(scalex=False)
File "C:\Anaconda2\lib\site-packages\matplotlib\axes\_base.py", line 2198, in autoscale_view
self.set_ybound(y0, y1)
File "C:\Anaconda2\lib\site-packages\matplotlib\axes\_base.py", line 2964, in set_ybound
self.set_ylim(lower, upper, auto=None)
File "C:\Anaconda2\lib\site-packages\matplotlib\axes\_base.py", line 3055, in set_ylim
self.callbacks.process('ylim_changed', self)
File "C:\Anaconda2\lib\site-packages\matplotlib\cbook.py", line 559, in process
"""
AttributeError: 'CallbackRegistry' object has no attribute 'callbacks'
Note I can edit the x axis range and the title by the code, however it's not convenient for me. Do you know how to edit saved plots by "Figure options" window of a figure window.
I use Python 2.7.11, Anaconda 2.4.1 (32-bit), matplotlib 1.5.1 on win32.