Skip to content
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 legend dragging. #16105

Merged
merged 1 commit into from Jan 6, 2020
Merged

Fix legend dragging. #16105

merged 1 commit into from Jan 6, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 5, 2020

Without this PR, after

plot([1, 2], label="foo"); legend().set_draggable(True)

when dragging the legend, releasing the mouse button results in

Traceback (most recent call last):
  File ".../matplotlib/cbook/__init__.py", line 236, in process
    func(*args, **kwargs)
  File ".../matplotlib/offsetbox.py", line 1716, in on_release
    self.finalize_offset()
  File ".../matplotlib/legend.py", line 78, in finalize_offset
    {"loc": self._update_loc, "bbox": self._bbox_to_anchor},
AttributeError: 'DraggableLegend' object has no attribute '_bbox_to_anchor'

See comment in code for more explanations.

A test may be nice but tricky to write...

Came in in #15086, so RC for 3.2.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Jan 5, 2020
@anntzer anntzer added this to the v3.2.0 milestone Jan 5, 2020
lib/matplotlib/legend.py Outdated Show resolved Hide resolved
Without this PR, after
```
plot([1, 2], label="foo"); legend().set_draggable(True)
```
when dragging the legend, releasing the mouse button results in
```
Traceback (most recent call last):
  File ".../matplotlib/cbook/__init__.py", line 236, in process
    func(*args, **kwargs)
  File ".../matplotlib/offsetbox.py", line 1716, in on_release
    self.finalize_offset()
  File ".../matplotlib/legend.py", line 78, in finalize_offset
    {"loc": self._update_loc, "bbox": self._bbox_to_anchor},
AttributeError: 'DraggableLegend' object has no attribute '_bbox_to_anchor'
```
See comment in code for more explanations.

A test may be nice but tricky to write...
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

post ci

@jklymak jklymak merged commit a6f5a28 into matplotlib:master Jan 6, 2020
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jan 6, 2020
@jklymak
Copy link
Member

jklymak commented Jan 6, 2020

I think in the future style fix PRs like #15086 should have 100% test coverage. If some part can't be tested, maybe make it its own PR?

@anntzer anntzer deleted the legenddrag branch January 6, 2020 17:16
@anntzer
Copy link
Contributor Author

anntzer commented Jan 6, 2020

sounds fair

QuLogic added a commit that referenced this pull request Jan 7, 2020
…105-on-v3.2.x

Backport PR #16105 on branch v3.2.x (Fix legend dragging.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants