Skip to content

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

Closed

Description

@anntzer

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.

Activity

  1. added this to the milestone on May 19, 2016
  2. tacaswell commented on May 19, 2016

    @tacaswell
    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.

  3. added a commit that references this issue on May 29, 2016
    722f405
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions