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 bf5eb3f

Browse filesBrowse files
committed
Only allow set_adjustable("datalim") for axes with standard data ratios.
If an Axes subclass overrides get_data_ratio to anything else than "ratio of data limits after application of scales" (e.g. Polar always returns 1), then the data limits manipulation in apply_aspect won't achieve the proper data ratio anyways, so disable setting adjustable to "datalim" in that case. For example, calling `axis("equal")` on polar axes (which also sets adjustable to "datalim") will now error out instead of resulting in a nonsensical plot.
1 parent 2d56d42 commit bf5eb3f
Copy full SHA for bf5eb3f

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

+12
-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_axs.get_siblings(self),
1321+
*self._shared_y_axs.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

0 commit comments

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