| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
LGTM. Needs a rebase
Sorry, something went wrong.
Previously, pickling and unpickling shared axes would result in axes sharing a ticker instance (because that's how shared axes are set up), but without changes of one's xlims propagated to the other. The reason is that that sharedness information is stored in AxesBase._shared_x_axes, which does *not* get pickled together with the Axes instance: the latter only has a textual reference "I am an instance of AxesBase", so the Grouper information is lost. To keep the Grouper information valid, instead move the Groupers to the instance dictionaries (as references to global groupers). Also make Groupers picklable following a similar strategy as Transforms, i.e. by transforming weakrefs into real refs when pickling and transforming them back into weakref when unpickling.
|
rebased |
Sorry, something went wrong.
|
I don't claim to fully understand what's going on here. However, all axes created in the session use the same global Grouper. In contrast, each set of axes that are created from one unpickling have a separate Grouper instance. I'm not sure that this really creates a problem, but it's an asymmetry that I wouldn't have expected. |
Sorry, something went wrong.
|
The observation is correct, but not a problem... until we decide to allow post-hoc modifications of the sharedness state. See also #9923. |
Sorry, something went wrong.
Does that mean that the usual ax1.get_shared_x_axes().join(ax1, ax2) isn't allowed? By whom? |
Sorry, something went wrong.
|
Well, I didn't know that API even existed (I think it qualifies as an API leak, but it's a nifty one...), so you have a point. |
Sorry, something went wrong.
|
I don't think it depends on whether the axes had been shared previously. In case of previously shared axes, you'd do import matplotlib.pyplot as plt
import pickle
fig, axes = plt.subplots(ncols=3, sharey="row")
axes[0].plot([0,1],[0,1])
axes[1].plot([0,1],[1,2])
axes[2].plot([0,1],[2,3])
pickle.dump(fig, file('fig1.pkl', 'wb'))
plt.close("all")
fig2 = pickle.load(file('fig1.pkl','rb'))
ax_master = fig2.axes[0]
for ax in fig2.axes:
if ax is not ax_master:
ax_master.get_shared_y_axes().join(ax_master, ax)
plt.show()
In case of previously unshared axes you can do the same: import matplotlib.pyplot as plt
import pickle
fig, axes = plt.subplots(ncols=3)
axes[0].plot([0,1],[0,1])
axes[1].plot([0,1],[1,2])
axes[2].plot([0,1],[2,3])
pickle.dump(fig, file('fig1.pkl', 'wb'))
plt.close("all")
fig2 = pickle.load(file('fig1.pkl','rb'))
ax_master = fig2.axes[0]
for ax in fig2.axes:
if ax is not ax_master:
ax_master.get_shared_y_axes().join(ax_master, ax)
ax.autoscale()
plt.show()
|
Sorry, something went wrong.
|
My point is that with this implementation, you can't reload two separately pickled axes and then share them, and I think that's a reasonable tradeoff in exchange of being able to correctly pickle and unpickle previously shared axes. |
Sorry, something went wrong.
|
I'm afraid that someone will stumble upon this limitation again. |
Sorry, something went wrong.
|
So the Grouper object has a (weak)ref to every axes that is involved in any sharing does this mean that every pickle will include all currently shared axes, they will all be restored on unpickle, and then any non-used ones will be immediately gc'd (or do they stick around)? I agree the detail that some Axes objects will use the global group and other axes (sets) will use their own private Grouper seems like a major gotcha bug. Suspect the fix will be to, in addition to this change, to prune the pickeled Grouper to just be things shared by current set of interest and then on restore to inject them selves back into the shared grouper. |
Sorry, something went wrong.
There was a problem hiding this comment.
A step in the right direction, but not convinced that the fix is worth the downside consequences.
Sorry, something went wrong.
|
Moved this to 3.1 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Previously, pickling and unpickling shared axes would result in
axes sharing a ticker instance (because that's how shared axes
are set up), but without changes of one's xlims propagated to the
other. The reason is that that sharedness information is stored in
AxesBase._shared_x_axes, which does not get pickled together with the
Axes instance: the latter only has a textual reference "I am an instance
of AxesBase", so the Grouper information is lost.
To keep the Grouper information valid, instead move the Groupers to the
instance dictionaries (as references to global groupers). Also make
Groupers picklable following a similar strategy as Transforms, i.e. by
transforming weakrefs into real refs when pickling and transforming them
back into weakref when unpickling.
PR Summary
PR Checklist