Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,9 +1274,10 @@ def sharex(self, other):
self._sharex = other
self.xaxis.major = other.xaxis.major # Ticker instances holding
self.xaxis.minor = other.xaxis.minor # locator and formatter.
# Set scale before limits to avoid warnings with non-linear scales
self.xaxis._scale = other.xaxis._scale
x0, x1 = other.get_xlim()
self.set_xlim(x0, x1, emit=False, auto=other.get_autoscalex_on())
self.xaxis._scale = other.xaxis._scale

def sharey(self, other):
"""
Expand All @@ -1293,9 +1294,10 @@ def sharey(self, other):
self._sharey = other
self.yaxis.major = other.yaxis.major # Ticker instances holding
self.yaxis.minor = other.yaxis.minor # locator and formatter.
# Set scale before limits to avoid warnings with non-linear scales
self.yaxis._scale = other.yaxis._scale
y0, y1 = other.get_ylim()
self.set_ylim(y0, y1, emit=False, auto=other.get_autoscaley_on())
self.yaxis._scale = other.yaxis._scale

def __clear(self):
"""Clear the Axes."""
Expand Down Expand Up @@ -1419,6 +1421,9 @@ def __clear(self):
share = getattr(self, f"_share{name}")
if share is not None:
getattr(self, f"share{name}")(share)
# Don't set default limits for shared axes - they will be
# synchronized from the shared axis and may have non-linear
# scales that would reject the (0, 1) default limits.
else:
# Although the scale was set to linear as part of clear,
# polar requires that _set_scale is called again
Expand Down
9 changes: 8 additions & 1 deletion lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,14 @@ def _set_lim(self, v0, v1, *, emit=True, auto):
for other in self._get_shared_axes():
if other is self.axes:
continue
other._axis_map[name]._set_lim(v0, v1, emit=False, auto=auto)
# Skip propagating default (0, 1) limits from linear scale to
Copy link
Member

Choose a reason for hiding this comment

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

Please convince me that this is the correct solution and not just fixing a special case. I don’t have full oversight on the details of the topic, but doing selective action on scale and limits doesn’t feel like it it’s a general solution.

# non-linear scales during clear operations to avoid warnings
other_axis = other._axis_map[name]
if (self.get_scale() == 'linear' and
other_axis.get_scale() != 'linear' and
v0 == 0 and v1 == 1):
continue
other_axis._set_lim(v0, v1, emit=False, auto=auto)
if emit:
other.callbacks.process(f"{name}lim_changed", other)
if ((other_fig := other.get_figure(root=False)) !=
Expand Down
Loading