File tree Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -542,17 +542,25 @@ def __getstate__(self):
542
542
# The renderer should be re-created by the figure, and then cached at
543
543
# that point.
544
544
state = super ().__getstate__ ()
545
- state ['_cachedRenderer' ] = None
546
- state .pop ('_layoutbox' )
547
- state .pop ('_poslayoutbox' )
548
-
545
+ for key in ['_cachedRenderer' , '_layoutbox' , '_poslayoutbox' ]:
546
+ state [key ] = None
547
+ # Prune the sharing & twinning info to only contain the current group.
548
+ for grouper_name in [
549
+ '_shared_x_axes' , '_shared_y_axes' , '_twinned_axes' ]:
550
+ grouper = getattr (self , grouper_name )
551
+ state [grouper_name ] = (grouper .get_siblings (self )
552
+ if self in grouper else None )
549
553
return state
550
554
551
555
def __setstate__ (self , state ):
556
+ # Merge the grouping info back into the global groupers.
557
+ for grouper_name in [
558
+ '_shared_x_axes' , '_shared_y_axes' , '_twinned_axes' ]:
559
+ siblings = state .pop (grouper_name )
560
+ if siblings :
561
+ getattr (self , grouper_name ).join (* siblings )
552
562
self .__dict__ = state
553
563
self ._stale = True
554
- self ._layoutbox = None
555
- self ._poslayoutbox = None
556
564
557
565
def get_window_extent (self , * args , ** kwargs ):
558
566
"""
Original file line number Diff line number Diff line change @@ -185,3 +185,10 @@ def test_rrulewrapper():
185
185
except RecursionError :
186
186
print ('rrulewrapper pickling test failed' )
187
187
raise
188
+
189
+
190
+ def test_shared ():
191
+ fig , axs = plt .subplots (2 , sharex = True )
192
+ fig = pickle .loads (pickle .dumps (fig ))
193
+ fig .axes [0 ].set_xlim (10 , 20 )
194
+ assert fig .axes [1 ].get_xlim () == (10 , 20 )
You can’t perform that action at this time.
0 commit comments