Skip to content

Commit a30f451

Browse files
authored
Merge pull request #7367 from cfackler/log-axis-limits-warning
Warn on invalid log axis limits, per issue #7299
2 parents f5c1f00 + 35cb8a5 commit a30f451

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/matplotlib/axes/_base.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -2823,7 +2823,7 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
28232823
For example, suppose *x* is years before present.
28242824
Then one might use::
28252825
2826-
set_ylim(5000, 0)
2826+
set_xlim(5000, 0)
28272827
28282828
so 5000 years ago is on the left of the plot and the
28292829
present is on the right.
@@ -2861,6 +2861,11 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
28612861
'in singular transformations; automatically expanding.\n'
28622862
'left=%s, right=%s') % (left, right))
28632863
left, right = mtransforms.nonsingular(left, right, increasing=False)
2864+
2865+
if self.get_xscale() == 'log' and (left <= 0.0 or right <= 0.0):
2866+
warnings.warn(
2867+
'Attempted to set non-positive xlimits for log-scale axis; '
2868+
'invalid limits will be ignored.')
28642869
left, right = self.xaxis.limit_range_for_scale(left, right)
28652870

28662871
self.viewLim.intervalx = (left, right)
@@ -3121,6 +3126,11 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
31213126
'bottom=%s, top=%s') % (bottom, top))
31223127

31233128
bottom, top = mtransforms.nonsingular(bottom, top, increasing=False)
3129+
3130+
if self.get_yscale() == 'log' and (bottom <= 0.0 or top <= 0.0):
3131+
warnings.warn(
3132+
'Attempted to set non-positive ylimits for log-scale axis; '
3133+
'invalid limits will be ignored.')
31243134
bottom, top = self.yaxis.limit_range_for_scale(bottom, top)
31253135

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

0 commit comments

Comments
 (0)