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

MNT: Warn if fixed aspect overwrites explicitly set data limits by timhoffm · Pull Request #28683 · matplotlib/matplotlib · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) 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
9 changes: 8 additions & 1 deletion 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 @@ -1705,7 +1705,8 @@ def set_adjustable(self, adjustable, share=False):
----------
adjustable : {'box', 'datalim'}
If 'box', change the physical dimensions of the Axes.
If 'datalim', change the ``x`` or ``y`` data limits.
If 'datalim', change the ``x`` or ``y`` data limits. This
may ignore explicitly defined axis limits.

timhoffm Aug 8, 2024 •
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Note: I've intentionally written may because in the current implementation one can have scenarios where the limits are respected. For example

fig, ax = plt.subplots()
ax.set_aspect('equal', 'datalim')
ax.plot([0, 1], [0, 2])
ax.set_ylim(-5, 5)

Just looking at the data, the y-range is larger, so to get all data shown on equal aspect, x has to be increased. Thus, new xlims are calculated, but taking the ylim (not the ydata) into account. Whether this behavior of sometimes taking limits into account and sometimes not is desireable, is a separate question that I don't want to discuss. The doc now only states that it may (or may not) happen. Note however, that the added runtime warning is precise: It will be emitted exactly if we change previously fixed limits.


share : bool, default: False
If ``True``, apply the settings to all shared Axes.
Expand Down Expand Up @@ -2022,11 +2023,17 @@ def apply_aspect(self, position=None):
yc = 0.5 * (ymin + ymax)
y0 = yc - Ysize / 2.0
y1 = yc + Ysize / 2.0
if not self.get_autoscaley_on():
_log.warning("Ignoring fixed y limits to fulfill fixed data aspect "
"with adjustable data limits.")
self.set_ybound(y_trf.inverted().transform([y0, y1]))
else:
xc = 0.5 * (xmin + xmax)
x0 = xc - Xsize / 2.0
x1 = xc + Xsize / 2.0
if not self.get_autoscalex_on():
_log.warning("Ignoring fixed x limits to fulfill fixed data aspect "
"with adjustable data limits.")
self.set_xbound(x_trf.inverted().transform([x0, x1]))

def axis(self, arg=None, /, *, emit=True, **kwargs):
Expand Down

Back | FazBrowse Home | New Git URL