FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Restore axes sharedness when unpickling. by anntzer · Pull Request #11544 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
20 changes: 14 additions & 6 deletions lib/matplotlib/axes/_base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -542,17 +542,25 @@ def __getstate__(self):
# The renderer should be re-created by the figure, and then cached at
# that point.
state = super().__getstate__()
state['_cachedRenderer'] = None
state.pop('_layoutbox')
state.pop('_poslayoutbox')

for key in ['_cachedRenderer', '_layoutbox', '_poslayoutbox']:
state[key] = None
# Prune the sharing & twinning info to only contain the current group.
for grouper_name in [
'_shared_x_axes', '_shared_y_axes', '_twinned_axes']:
grouper = getattr(self, grouper_name)
state[grouper_name] = (grouper.get_siblings(self)
if self in grouper else None)
return state

def __setstate__(self, state):
# Merge the grouping info back into the global groupers.
for grouper_name in [
'_shared_x_axes', '_shared_y_axes', '_twinned_axes']:
siblings = state.pop(grouper_name)
if siblings:
getattr(self, grouper_name).join(*siblings)
self.__dict__ = state
self._stale = True
self._layoutbox = None
self._poslayoutbox = None

def get_window_extent(self, *args, **kwargs):
"""
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_pickle.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,10 @@ def test_rrulewrapper():
except RecursionError:
print('rrulewrapper pickling test failed')
raise


def test_shared():
fig, axs = plt.subplots(2, sharex=True)
fig = pickle.loads(pickle.dumps(fig))
fig.axes[0].set_xlim(10, 20)
assert fig.axes[1].get_xlim() == (10, 20)

Back | FazBrowse Home | New Git URL