File tree 3 files changed +25
-0
lines changed
3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -788,6 +788,19 @@ class Grouper:
788
788
def __init__ (self , init = ()):
789
789
self ._mapping = {weakref .ref (x ): [weakref .ref (x )] for x in init }
790
790
791
+ def _as_strong_dict (self ):
792
+ """Export the grouper's weak refs to strong refs; useful for pickling."""
793
+ self .clean ()
794
+ return {k (): [v () for v in vs ] for k , vs in self ._mapping .items ()}
795
+
796
+ @classmethod
797
+ def _from_strong_dict (cls , mapping ):
798
+ """Create a grouper from a dict of strong refs; useful for unpickling."""
799
+ self = cls ()
800
+ self ._mapping = {weakref .ref (k ): [* map (weakref .ref , vs )]
801
+ for k , vs in mapping .items ()}
802
+ return self
803
+
791
804
def __contains__ (self , item ):
792
805
return weakref .ref (item ) in self ._mapping
793
806
Original file line number Diff line number Diff line change @@ -3174,6 +3174,10 @@ def __getstate__(self):
3174
3174
from matplotlib import _pylab_helpers
3175
3175
if self .canvas .manager in _pylab_helpers .Gcf .figs .values ():
3176
3176
state ['_restore_to_pylab' ] = True
3177
+
3178
+ state ["_align_label_groups" ] = {
3179
+ k : v ._as_strong_dict () for k , v in self ._align_label_groups .items ()}
3180
+
3177
3181
return state
3178
3182
3179
3183
def __setstate__ (self , state ):
@@ -3201,6 +3205,10 @@ def __setstate__(self, state):
3201
3205
pylab_helpers .Gcf ._set_new_active_manager (mgr )
3202
3206
plt .draw_if_interactive ()
3203
3207
3208
+ self ._align_label_groups = {
3209
+ k : cbook .Grouper ._from_strong_dict (v )
3210
+ for k , v in self ._align_label_groups .items ()}
3211
+
3204
3212
self .stale = True
3205
3213
3206
3214
def add_axobserver (self , func ):
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ def _generate_complete_test_figure(fig_ref):
58
58
# Ensure lists also pickle correctly.
59
59
plt .subplot (3 , 3 , 1 )
60
60
plt .plot (list (range (10 )))
61
+ plt .ylabel ("hello" )
61
62
62
63
plt .subplot (3 , 3 , 2 )
63
64
plt .contourf (data , hatches = ['//' , 'ooo' ])
@@ -68,6 +69,7 @@ def _generate_complete_test_figure(fig_ref):
68
69
69
70
plt .subplot (3 , 3 , 4 )
70
71
plt .imshow (data )
72
+ plt .ylabel ("hello\n world!" )
71
73
72
74
plt .subplot (3 , 3 , 5 )
73
75
plt .pcolor (data )
@@ -89,6 +91,8 @@ def _generate_complete_test_figure(fig_ref):
89
91
plt .subplot (3 , 3 , 9 )
90
92
plt .errorbar (x , x * - 0.5 , xerr = 0.2 , yerr = 0.4 )
91
93
94
+ fig_ref .align_ylabels () # Test handling of _align_label_groups Groupers.
95
+
92
96
93
97
@mpl .style .context ("default" )
94
98
@check_figures_equal (extensions = ["png" ])
You can’t perform that action at this time.
0 commit comments