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

Skip to content

Commit 677e97d

Browse files
committed
Actually ignore invalid log-axis limit setting
1 parent 3664c83 commit 677e97d

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,10 +3047,20 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
30473047
'left=%s, right=%s') % (left, right))
30483048
left, right = mtransforms.nonsingular(left, right, increasing=False)
30493049

3050-
if self.get_xscale() == 'log' and (left <= 0.0 or right <= 0.0):
3051-
warnings.warn(
3052-
'Attempted to set non-positive xlimits for log-scale axis; '
3053-
'invalid limits will be ignored.')
3050+
if self.get_xscale() == 'log':
3051+
if left <= 0.0:
3052+
warnings.warn(
3053+
'Attempted to set non-positive left xlim on a '
3054+
'log-scaled axis.\n'
3055+
'Invalid limit will be ignored.')
3056+
left = old_left
3057+
if right <= 0.0:
3058+
warnings.warn(
3059+
'Attempted to set non-positive right xlim on a '
3060+
'log-scaled axis.\n'
3061+
'Invalid limit will be ignored.')
3062+
right = old_right
3063+
30543064
left, right = self.xaxis.limit_range_for_scale(left, right)
30553065

30563066
self.viewLim.intervalx = (left, right)
@@ -3367,10 +3377,19 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
33673377

33683378
bottom, top = mtransforms.nonsingular(bottom, top, increasing=False)
33693379

3370-
if self.get_yscale() == 'log' and (bottom <= 0.0 or top <= 0.0):
3371-
warnings.warn(
3372-
'Attempted to set non-positive ylimits for log-scale axis; '
3373-
'invalid limits will be ignored.')
3380+
if self.get_yscale() == 'log':
3381+
if bottom <= 0.0:
3382+
warnings.warn(
3383+
'Attempted to set non-positive bottom ylim on a '
3384+
'log-scaled axis.\n'
3385+
'Invalid limit will be ignored.')
3386+
bottom = old_bottom
3387+
if top <= 0.0:
3388+
warnings.warn(
3389+
'Attempted to set non-positive top ylim on a '
3390+
'log-scaled axis.\n'
3391+
'Invalid limit will be ignored.')
3392+
top = old_top
33743393
bottom, top = self.yaxis.limit_range_for_scale(bottom, top)
33753394

33763395
self.viewLim.intervaly = (bottom, top)

0 commit comments

Comments
 (0)