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

LineCollection.contains does not include caps around vertices, unlike Line2D.contains #17279

Open
anntzer opened this issue Apr 30, 2020 · 1 comment
Labels
API: consistency keep Items to be ignored by the “Stale” Github Action

Comments

@anntzer
Copy link
Contributor

anntzer commented Apr 30, 2020

Bug report

Bug summary

Line2D.contains returns True for clicks just "beyond" the vertices of the Line2D, as long as they're not more than pickradius away from the vertex. On the contrary, LineCollection returns False for any click that's beyond the vertices.
In particular, this can make it difficult to click on "short" LineCollections.

Code for reproduction

from matplotlib import pyplot as plt
from matplotlib.backend_bases import MouseEvent
import numpy as np

fig, axs = plt.subplots(2)
line, = axs[0].plot([-1, 1], [0, 0])
coll = axs[1].hlines(0, -1, 1)

fig.canvas.draw()

for ax, art in zip(axs, [line, coll]):
    ax.set(xlim=(-2, 2), ylim=(-.5, .5))
    art.set_pickradius(20)
    for x in np.linspace(*ax.get_xlim())[1:-1]:
        for y in np.linspace(*ax.get_ylim())[1:-1]:
            x1, y1 = ax.transData.transform((x, y))
            contained, _ = art.contains(
                MouseEvent("button_press_event", fig.canvas, x1, y1))
            ax.plot(x, y, "o", c="g" if contained else "r", ms=1)

plt.show()

Actual outcome

test
Green points are considered as "contained".

Expected outcome

Same green points above and below, with round "caps" at the ends.

Matplotlib version

  • Operating system: linux
  • Matplotlib version: master, likely since a very long time
  • Matplotlib backend (print(matplotlib.get_backend())): any
  • Python version: 38
  • Jupyter version (if applicable): no
  • Other libraries: no
@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jul 28, 2023
@anntzer anntzer added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: consistency keep Items to be ignored by the “Stale” Github Action
Projects
None yet
Development

No branches or pull requests

2 participants