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

Skip to content

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

Merged
merged 2 commits into from
Jun 30, 2019

Conversation

astrofrog
Copy link
Contributor

This fixes an issue that caused the following error when setting negative limits on a log plot:

Traceback (most recent call last):
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/external/echo/qt/connect.py", line 480, in update_prop
    setattr(self._instance, self._prop, data_wrapper.data)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/external/echo/core.py", line 264, in __setattr__
    super(HasCallbackProperties, self).__setattr__(attribute, value)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/external/echo/selection.py", line 39, in __set__
    super(SelectionCallbackProperty, self).__set__(instance, value)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/external/echo/core.py", line 79, in __set__
    self.notify(instance, old, new)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/utils/matplotlib.py", line 170, in wrapper
    result = func(*args, **kwargs)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/viewers/matplotlib/state.py", line 34, in notify
    super(DeferredDrawSelectionCallbackProperty, self).notify(*args, **kwargs)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/external/echo/core.py", line 128, in notify
    cback(new)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/core/state_objects.py", line 198, in _update_attribute
    self.update_values(attribute=self.component_id, use_default_modifiers=True)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/core/state_objects.py", line 378, in update_values
    self.set(lower=lower, upper=upper, percentile=percentile, log=log)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/core/state_objects.py", line 247, in set
    setattr(self, prop, value)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/external/echo/core.py", line 541, in __exit__
    p.notify(*args)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/utils/matplotlib.py", line 165, in wrapper
    return func(*args, **kwargs)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/viewers/matplotlib/state.py", line 23, in notify
    super(DeferredDrawCallbackProperty, self).notify(*args, **kwargs)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/external/echo/core.py", line 128, in notify
    cback(new)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/utils/matplotlib.py", line 165, in wrapper
    return func(*args, **kwargs)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/utils/matplotlib.py", line 165, in wrapper
    return func(*args, **kwargs)
  File "/Users/tom/Dropbox/Code/Glue/glue/glue/viewers/matplotlib/viewer.py", line 187, in limits_to_mpl
    self.axes.set_xlim(x_min, x_max)
  File "/Users/tom/tmp/matplotlib/lib/matplotlib/axes/_base.py", line 3282, in set_xlim
    left = old_left
UnboundLocalError: local variable 'old_left' referenced before assignment

@@ -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.
Copy link
Contributor

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"): ...?

Copy link
Contributor Author

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

@astrofrog astrofrog force-pushed the fix-negative-log-limits branch from 3fc50c7 to 94ac78a Compare June 26, 2019 14:52
@@ -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):
Copy link
Contributor

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?

@astrofrog
Copy link
Contributor Author

I'm investigating the test failures

@astrofrog astrofrog force-pushed the fix-negative-log-limits branch from bbe2147 to e71f881 Compare June 27, 2019 10:34
@astrofrog
Copy link
Contributor Author

@anntzer - I think this is ready for a final review. The AppVeyor failure seems to be unrelated.

@anntzer anntzer added this to the v3.2.0 milestone Jun 27, 2019
@anntzer
Copy link
Contributor

anntzer commented Jun 27, 2019

Milestoning as 3.2 as I think the bug is only on master?

@astrofrog
Copy link
Contributor Author

@anntzer - I didn't run into the issue with older versions so I think 3.2 makes sense.

@timhoffm timhoffm merged commit 32a111b into matplotlib:master Jun 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants