-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix bug when setting negative limits and using log scale #14635
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
Fix bug when setting negative limits and using log scale #14635
Conversation
lib/matplotlib/axes/_base.py
Outdated
@@ -3240,10 +3240,11 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, | |||
left = self._validate_converted_limits(left, self.convert_xunits) | |||
right = self._validate_converted_limits(right, self.convert_xunits) | |||
|
|||
old_left, old_right = self.get_xlim() | |||
|
|||
if left is None or right is None: | |||
# Axes init calls set_xlim(0, 1) before get_xlim() can be called, | |||
# so only grab the limits if we really need them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the comment here, I'd assume that this actually needs to stay here (... for init order purposes) and you need to duplicate the call to get_xlim() under if self.get_xscale("log"): ...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops yes, I've fixed that
3fc50c7
to
94ac78a
Compare
@@ -3249,7 +3249,10 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, | |||
if right is None: | |||
right = old_right | |||
|
|||
if self.get_xscale() == 'log': | |||
if self.get_xscale() == 'log' and (left <= 0 or right <= 0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likely the same is needed for set_ylim?
I'm investigating the test failures |
bbe2147
to
e71f881
Compare
@anntzer - I think this is ready for a final review. The AppVeyor failure seems to be unrelated. |
Milestoning as 3.2 as I think the bug is only on master? |
@anntzer - I didn't run into the issue with older versions so I think 3.2 makes sense. |
This fixes an issue that caused the following error when setting negative limits on a log plot: