From bf0dfdefae5feca4ba36a71c216a5a5cab44abda Mon Sep 17 00:00:00 2001 From: Cameron Fackler Date: Sun, 30 Oct 2016 22:32:26 -0400 Subject: [PATCH 1/3] Warn on invalid log axis limits, per issue #7299 An attempt to call set_xlim() or set_ylim() with non-positive limits on a log-scale axis will produce a warning. --- lib/matplotlib/axes/_base.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 91c0e3404d12..f1d6351c7970 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -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; ' + 'automatically adjusting.') left, right = self.xaxis.limit_range_for_scale(left, right) self.viewLim.intervalx = (left, right) @@ -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; ' + 'automatically adjusting.') bottom, top = self.yaxis.limit_range_for_scale(bottom, top) self.viewLim.intervaly = (bottom, top) From 1f675ad2af477a3f19ca11c523ee66510d0a8e4f Mon Sep 17 00:00:00 2001 From: Cameron Fackler Date: Sun, 30 Oct 2016 22:40:03 -0400 Subject: [PATCH 2/3] Fix typo in set_xlim() docstring --- lib/matplotlib/axes/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index f1d6351c7970..1ccd1b846cf6 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -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. From 35cb8a5202b8a393a1092bfaae3832eadc0c84ab Mon Sep 17 00:00:00 2001 From: Cameron Fackler Date: Mon, 31 Oct 2016 07:45:16 -0400 Subject: [PATCH 3/3] Update invalid axis limit warning message --- lib/matplotlib/axes/_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 1ccd1b846cf6..0977ee37b737 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2865,7 +2865,7 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw): 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; ' - 'automatically adjusting.') + 'invalid limits will be ignored.') left, right = self.xaxis.limit_range_for_scale(left, right) self.viewLim.intervalx = (left, right) @@ -3130,7 +3130,7 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw): 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; ' - 'automatically adjusting.') + 'invalid limits will be ignored.') bottom, top = self.yaxis.limit_range_for_scale(bottom, top) self.viewLim.intervaly = (bottom, top)