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

Skip to content

Line2D.contains does not take drawstyle into account. #6447

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

Closed
anntzer opened this issue May 19, 2016 · 1 comment · Fixed by #6497
Closed

Line2D.contains does not take drawstyle into account. #6447

anntzer opened this issue May 19, 2016 · 1 comment · Fixed by #6497
Milestone

Comments

@anntzer
Copy link
Contributor

anntzer commented May 19, 2016

See joferkington/mpldatacursor#36.
Briefly, Line2D.contains currently assumes that points in the line are connected by straight segments, thus ignoring drawstyle. Minimal example (edited from the event handling doc):

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title('click on points')

line, = ax.plot(np.random.rand(10), picker=5, drawstyle="steps-pre")  # 5 points tolerance

def onpick(event):
    thisline = event.artist
    xdata = thisline.get_xdata()
    ydata = thisline.get_ydata()
    ind = event.ind
    points = tuple(zip(xdata[ind], ydata[ind]))
    print('onpick points:', points)

fig.canvas.mpl_connect('pick_event', onpick)

plt.show()

Clicking on the drawn line does not always trigger an event. Clicking on the not-drawn "straight" segments connecting the data points does.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone May 19, 2016
@tacaswell
Copy link
Member

I think the solution is to pass the array of actually drawn points into the path handling instead of the data points. The Line2D code is a bit hairy so I have not guess how hard that would actually be.

anntzer added a commit to anntzer/matplotlib that referenced this issue May 29, 2016
For stepping drawstyles, `Line2D.draw` used to recompute a path at
drawing time, because its `_path` attribute always assumed a linear
drawstyle.  Instead, directly compute the correct path.

Also fixes matplotlib#6447 (`Line2D.contains` did not take drawstyle into account)
because that code relied on proximity of the mouse event with the
underlying path.
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 a pull request may close this issue.

2 participants