Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 277c042

Browse filesBrowse files
authored
Merge pull request #14835 from anntzer/adjustablestandardratio
Only allow set_adjustable("datalim") for axes with standard data ratios.
2 parents e41f5a1 + 2cc8e14 commit 277c042
Copy full SHA for 277c042

File tree

Expand file treeCollapse file tree

2 files changed

+18
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-4
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+12-4Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,11 +1317,19 @@ def set_adjustable(self, adjustable, share=False):
13171317
"""
13181318
cbook._check_in_list(["box", "datalim"], adjustable=adjustable)
13191319
if share:
1320-
axes = {*self._shared_x_axes.get_siblings(self),
1321-
*self._shared_y_axes.get_siblings(self)}
1320+
axs = {*self._shared_x_axes.get_siblings(self),
1321+
*self._shared_y_axes.get_siblings(self)}
13221322
else:
1323-
axes = [self]
1324-
for ax in axes:
1323+
axs = [self]
1324+
if (adjustable == "datalim"
1325+
and any(getattr(ax.get_data_ratio, "__func__")
1326+
!= _AxesBase.get_data_ratio
1327+
for ax in axs)):
1328+
# Limits adjustment by apply_aspect assumes that the axes' aspect
1329+
# ratio can be computed from the data limits and scales.
1330+
raise ValueError("Cannot set axes adjustable to 'datalim' for "
1331+
"Axes which override 'get_data_ratio'")
1332+
for ax in axs:
13251333
ax._adjustable = adjustable
13261334
self.stale = True
13271335

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4724,6 +4724,12 @@ def test_shared_with_aspect_3():
47244724
assert round(expected, 4) == round(ax.get_aspect(), 4)
47254725

47264726

4727+
def test_polar_not_datalim_adjustable():
4728+
ax = plt.figure().add_subplot(projection="polar")
4729+
with pytest.raises(ValueError):
4730+
ax.set_adjustable("datalim")
4731+
4732+
47274733
@pytest.mark.parametrize('twin', ('x', 'y'))
47284734
def test_twin_with_aspect(twin):
47294735
fig, ax = plt.subplots()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.