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

BUG: raise ValueError if sharex, sharey point to a different figure by efiring · Pull Request #6463 · matplotlib/matplotlib · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types 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
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
@@ -0,0 +1,8 @@
Axis-sharing between figures is blocked
```````````````````````````````````````

An attempt to share an axis between ``Axes`` objects in different
figures will now raise a ValueError. Previously such sharing
was allowed but could lead to an endless loop when combined
with fixed aspect ratios, as in the case of ``imshow``, for
example.
18 changes: 11 additions & 7 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 @@ -435,9 +435,9 @@ def __init__(self, fig, rect,

Optional keyword arguments:

================ =========================================
================ ==============================================
Keyword Description
================ =========================================
================ ==============================================
*adjustable* [ 'box' | 'datalim' | 'box-forced']
*alpha* float: the alpha transparency (can be None)
*anchor* [ 'C', 'SW', 'S', 'SE', 'E', 'NE', 'N',
Expand All @@ -458,10 +458,10 @@ def __init__(self, fig, rect,
toolbar button status
*position* [left, bottom, width, height] in
class:`~matplotlib.figure.Figure` coords
*sharex* an class:`~matplotlib.axes.Axes` instance
to share the x-axis with
*sharey* an class:`~matplotlib.axes.Axes` instance
to share the y-axis with
*sharex* another class:`~matplotlib.axes.Axes` instance
in *fig* to share the x-axis with
*sharey* another class:`~matplotlib.axes.Axes` instance
in *fig* to share the y-axis with
*title* the title string
*visible* [ *True* | *False* ] whether the axes is
visible
Expand All @@ -475,7 +475,7 @@ def __init__(self, fig, rect,
*yscale* [%(scale)s]
*yticklabels* sequence of strings
*yticks* sequence of floats
================ =========================================
================ ==============================================
""" % {'scale': ' | '.join(
[repr(x) for x in mscale.get_scale_names()])}
martist.Artist.__init__(self)
Expand All @@ -494,13 +494,17 @@ def __init__(self, fig, rect,
self._sharex = sharex
self._sharey = sharey
if sharex is not None:
if sharex.get_figure() is not fig:
raise ValueError('Shared Axes must be in the same figure')
self._shared_x_axes.join(self, sharex)
if sharex._adjustable == 'box':
sharex._adjustable = 'datalim'
# warnings.warn(
# 'shared axes: "adjustable" is being changed to "datalim"')
self._adjustable = 'datalim'
if sharey is not None:
if sharey.get_figure() is not fig:
raise ValueError('Shared Axes must be in the same figure')
self._shared_y_axes.join(self, sharey)
if sharey._adjustable == 'box':
sharey._adjustable = 'datalim'
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_axes.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 @@ -4220,6 +4220,15 @@ def test_empty_shared_subplots():
assert y1 >= 6


def test_shared_fig_fails():
# Github Issue #2790, sharing works only within a figure
fig, ax = plt.subplots()
with pytest.raises(ValueError):
plt.subplots(sharex=ax)
with pytest.raises(ValueError):
plt.subplots(sharey=ax)


def test_relim_visible_only():
x1 = (0., 10.)
y1 = (0., 10.)
Expand Down

Back | FazBrowse Home | New Git URL