🌐 AI搜索 & 代理 主页
Skip to content

Commit 2321eab

Browse files
author
Saumya
committed
FIX: Prevent warning when clearing axes with shared non-linear scale
When clearing an axes (via cla() or clf()) that has a shared axis with a non-linear scale (e.g., log, logit), a warning was incorrectly generated: 'Attempt to set non-positive xlim on a log-scaled axis will be ignored.' This occurred because the clear operation set default limits (0, 1) with emit=True, causing the limits to propagate to shared axes that still had non-linear scales which reject these limits. Fixed by using emit=False when setting default limits during clear, preventing propagation to shared axes. Fixes #9970
1 parent 702c669 commit 2321eab

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,12 +1419,18 @@ def __clear(self):
14191419
share = getattr(self, f"_share{name}")
14201420
if share is not None:
14211421
getattr(self, f"share{name}")(share)
1422+
# Don't set default limits for shared axes - they will be
1423+
# synchronized from the shared axis and may have non-linear
1424+
# scales that would reject the (0, 1) default limits.
14221425
else:
14231426
# Although the scale was set to linear as part of clear,
14241427
# polar requires that _set_scale is called again
14251428
if self.name == "polar":
14261429
axis._set_scale("linear")
1427-
axis._set_lim(0, 1, auto=True)
1430+
# Use emit=False to prevent propagating (0, 1) default limits
1431+
# to shared axes that may have non-linear scales (e.g., 'log')
1432+
# that would reject these limits and generate a warning.
1433+
axis._set_lim(0, 1, emit=False, auto=True)
14281434
self._update_transScale()
14291435

14301436
self.stale = True

0 commit comments

Comments
 (0)