Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbe2147

Browse files
committed
Apply fix for invalid limits in log scale to y axis
1 parent 94ac78a commit bbe2147

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3632,7 +3632,10 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
36323632
if top is None:
36333633
top = old_top
36343634

3635-
if self.get_yscale() == 'log':
3635+
if self.get_xscale() == 'log' and (bottom <= 0 or top <= 0):
3636+
# Axes init calls set_xlim(0, 1) before get_xlim() can be called,
3637+
# so only grab the limits if we really need them.
3638+
old_bottom, old_top = self.get_ylim()
36363639
if bottom <= 0:
36373640
cbook._warn_external(
36383641
'Attempted to set non-positive bottom ylim on a '

lib/matplotlib/tests/test_axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,9 @@ def test_log_scales_invalid():
21472147
ax.set_xscale('log')
21482148
with pytest.warns(UserWarning, match='Attempted to set non-positive'):
21492149
ax.set_xlim(-1, 10)
2150+
ax.set_yscale('log')
2151+
with pytest.warns(UserWarning, match='Attempted to set non-positive'):
2152+
ax.set_ylim(-1, 10)
21502153

21512154

21522155
@image_comparison(['stackplot_test_image', 'stackplot_test_image'])

0 commit comments

Comments
 (0)