I am storing pickled Figures for plotting at later time but for some reason the sharedx property keeps getting lost on the 2nd (unpickled) figure. Execute the code below for a quick example. Is there a way to reset the shared x property? There is PR 1312 that talks about a potential unshare_x_axes function but there doesn't really appear to be a setting function either. This may actually be two problems though since the pickle should also maintain the sharedx property.
#!/usr/bin/env pythonimportcPickleaspickleimportmatplotlib.pyplotaspltimportnumpyasnp# Simple data to display in various formsx=np.linspace(0, 2*np.pi, 400)
y=np.sin(x**2)
f, axarr=plt.subplots(2, sharex=True)
axarr[0].plot(x, y)
axarr[0].set_title('Sharing X axis')
axarr[1].scatter(x, y)
pickle.dump(f,open('test.pickle','wb'))
new_plot=pickle.load(open('test.pickle','rb'))
new_plot.canvas.draw()
plt.show()
Sharex is implemented by holding a reference to the other Axes/Axis objects (I do not recall which off the top of my head). There obviously do not survive round tripping. The way to fix this would be to work on__setstate__ / __getstate__ of the Axes object to replace the Grouper data structure with a list of uids, to make sure that all of the Axes objects have those uids assigned to them, and then at the end of __getstate__ in Figure replace the uids back. To make this more fun, the Grouper objects are actually class-level attributes.
We do not officially encourage using pickle objects to serialize figures, the 'official' way is the function that you used to generate the figure.
I implemented a work around by pickling a custom python dictionary stuffed
with the plotting data and other plot info, e.g. title,xLabel,yLabel,
etc,. Then used custom plotting function that accepted the dictionary
object and re-created the plot.
Sharex is implemented by holding a reference to the other Axes/Axis
objects (I do not recall which off the top of my head). There obviously do
not survive round tripping. The way to fix this would be to work on setstate / getstate of the Axes object to replace the Grouper
data structure with a list of uids, to make sure that all of the Axes
objects have those uids assigned to them, and then at the end of getstate in Figure replace the uids back. To make this more fun,
the Grouper objects are actually class-level attributes.
We do not officially encourage using pickle objects to serialize figures,
the 'official' way is the function that you used to generate the figure.
—
Reply to this email directly or view it on GitHub #4827 (comment)
.
Activity
freidrichen commented on Mar 2, 2016
I'm also affected by this issue. Any progress or good workarounds?
tacaswell commented on Mar 2, 2016
Sharex is implemented by holding a reference to the other Axes/Axis objects (I do not recall which off the top of my head). There obviously do not survive round tripping. The way to fix this would be to work on__setstate__ / __getstate__ of the Axes object to replace the Grouper data structure with a list of uids, to make sure that all of the Axes objects have those uids assigned to them, and then at the end of __getstate__ in Figure replace the uids back. To make this more fun, the Grouper objects are actually class-level attributes.
We do not officially encourage using pickle objects to serialize figures, the 'official' way is the function that you used to generate the figure.
spaceluigi commented on Apr 12, 2016
I implemented a work around by pickling a custom python dictionary stuffed
with the plotting data and other plot info, e.g. title,xLabel,yLabel,
etc,. Then used custom plotting function that accepted the dictionary
object and re-created the plot.
On Wed, Mar 2, 2016, 2:19 PM Thomas A Caswell notifications@github.com
wrote:
tacaswell commented on Apr 12, 2016
@lugi5720 That is a preferred way