Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@eschutz
Copy link
Contributor

@eschutz eschutz commented Apr 16, 2018

PR Summary

Fixed an issue where Ellipses would not move when ellipse.center was set.

Example:

import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse

def onmove(event):
    ellipse.center = event.xdata, event.ydata
    # ellipse.stale = True # (old fix)
    # Ellipse position would not update after plt.draw()
    # Should move with mouse
    plt.draw()

ellipse = Ellipse((1,1), 1, 1)
plt.gca().add_patch(ellipse)
plt.gca().set_aspect('equal')
plt.gcf().canvas.mpl_connect('motion_notify_event', onmove)
plt.xlim(0, 4)
plt.ylim(0, 4)
plt.show()

Old
old
New
new

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 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

Patch.__init__(self, **kwargs)

self.center = xy
self.xy = xy
Copy link
Member

Choose a reason for hiding this comment

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

I'd use self._center instead of self.xy. We shouldn't add a public attribute. While xy is used as a variable name in __init__, I don't think it's a good choice. "center" is more semantic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to self._center, thanks!

@ImportanceOfBeingErnest
Copy link
Member

This for sure breaks a lot of existing code. Ellipse and Circle not having setters for the center position, using Circle.center is the widely adopted way to change their position. One should not silently remove this attribute.
I suspect, being an attribute, it's somehow hard to deprecate via warnings issued; but I don't think this qualifies as a reason to let it disappear completely unnoticed from one version to next.

I personally do not quite see the reason to hide the attribute, but if people think this should be done, it should be done for all attributes of all patches and the respective setters and getters should be introduced.

@eschutz
Copy link
Contributor Author

eschutz commented Apr 16, 2018

The Ellipse.center attribute is still there, it’s just accessed through the getter and setter: center = property(get_center, set_center). This is the same way Circle.radius is implemented.

@ImportanceOfBeingErnest
Copy link
Member

omg, I did not see that. Sorry. All good.

@timhoffm timhoffm merged commit 5daabdd into matplotlib:master Apr 16, 2018
@dstansby
Copy link
Member

Thanks for what looks like your first contribution @eschutz!

@eschutz
Copy link
Contributor Author

eschutz commented Apr 16, 2018

Thank you!

@eschutz eschutz deleted the ellipse-center branch April 16, 2018 22:26
@QuLogic QuLogic added this to the v3.0 milestone Apr 17, 2018
@QuLogic
Copy link
Member

QuLogic commented Apr 17, 2018

I think we should move away from this set/get style and use the @property decorator form instead.

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.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.