Skip to content

Warn on invalid log axis limits, per issue #7299 #7367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 31, 2016
Merged
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
12 changes: 11 additions & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2823,7 +2823,7 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
For example, suppose *x* is years before present.
Then one might use::

set_ylim(5000, 0)
set_xlim(5000, 0)

so 5000 years ago is on the left of the plot and the
present is on the right.
Expand Down Expand Up @@ -2861,6 +2861,11 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
'in singular transformations; automatically expanding.\n'
'left=%s, right=%s') % (left, right))
left, right = mtransforms.nonsingular(left, right, increasing=False)

if self.get_xscale() == 'log' and (left <= 0.0 or right <= 0.0):
warnings.warn(
'Attempted to set non-positive xlimits for log-scale axis; '
'invalid limits will be ignored.')
left, right = self.xaxis.limit_range_for_scale(left, right)

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

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

if self.get_yscale() == 'log' and (bottom <= 0.0 or top <= 0.0):
warnings.warn(
'Attempted to set non-positive ylimits for log-scale axis; '
'invalid limits will be ignored.')
bottom, top = self.yaxis.limit_range_for_scale(bottom, top)

self.viewLim.intervaly = (bottom, top)
Expand Down