-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[ENH]: pickle (or save) matplotlib figure with insteractive slider #22482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
diff --git i/lib/matplotlib/widgets.py w/lib/matplotlib/widgets.py
index 16e03f5624..a9f1145bf2 100644
--- i/lib/matplotlib/widgets.py
+++ w/lib/matplotlib/widgets.py
@@ -115,9 +115,10 @@ class AxesWidget(Widget):
def __init__(self, ax):
self.ax = ax
- self.canvas = ax.figure.canvas
self._cids = []
+ canvas = property(lambda self: self.ax.figure.canvas)
+
def connect_event(self, event, callback):
"""
Connect a callback function with an event. "fixes" the pickling itself (and seems like a reasonable patch regardless), but even then, the pickling process will drop any connected callbacks as functions can generally not be pickled. |
@anntzer is the dropping of callbacks when picking a figure builtin matplotlib ? or is it a limitation of the standard pickle module ? or is there some kind of criterion that make a function pickle-able or not ? I am in the same kind of situation as @LucaAmerio, where I create matplotlib figure (with Qt backend) and callbacks connected to the figure and/or the axes. I'd like to be able to save and re-open those figure with the callbacks still active |
The ability to pickle functions is limited per https://docs.python.org/3/library/pickle.html#what-can-be-pickled-and-unpickled. We could consider pickling only whatever can actually be pickled and drop the rest, but I believe dropping everything (and asking whoever does the unpickling to reconnect things as needed) is not unreasonable either. |
Problem
I'd like to save/pickle a matplotlib figure containing a
matplotlib.widgets.Widget
object to send it to a colleague without him having to run the code I use to generate it.I know since matplotlib version 1.2
matplotlib.figure.Figure
are pickable. However, when the figure contains amatplotlib.widgets.Widget
, pickle fails to save it.For example consider this class:
If I run
all works properly. However
returns
Is there a way to workaround this?
DISCLAIMER: The same question was posted here https://stackoverflow.com/questions/71145817/pickle-or-save-matplotlib-figure-with-insteractive-slider
Proposed solution
No response
The text was updated successfully, but these errors were encountered: