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 (ab)uses pickradius<=0 as marker for "filled" #17281

Open
anntzer opened this issue Apr 30, 2020 · 1 comment
Open

LineCollection.contains (ab)uses pickradius<=0 as marker for "filled" #17281

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

When the pickradius of a LineCollection is set to a <=0 value, LineCollection.contains treats the polygon as "closed".

Code for reproduction

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

fig, axs = plt.subplots(2)

for ax, pr in zip(axs, [0, 10]):
    coll = LineCollection([[(0, 0), (1, 0), (0, 1)]])
    ax.add_collection(coll)
    ax.set(xlim=(-1, 2), ylim=(-1, 2))
    coll.set_pickradius(pr)
    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, _ = coll.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

Note how on the top LineCollection (using pickradius=0), all points "in" the closed polygon are considered "contained".

Expected outcome

Only points exactly on the LineCollection are contained for pickradius = 0, no points are contained for pickradius < 0 (consistently with Line2D).


The relevant code is in Line2D.contains:

        ind = _path.point_in_path_collection(
            mouseevent.x, mouseevent.y, pickradius,
            transform.frozen(), paths, self.get_transforms(),
            offsets, transOffset, pickradius <= 0,  # <--- this last argument is "filled"
            self._offset_position)

Matplotlib version

  • Operating system: linux
  • Matplotlib version: master, likely since a long time ago
  • 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
@github-actions github-actions bot added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label Aug 28, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 28, 2023
@timhoffm timhoffm added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. labels Aug 28, 2023
@timhoffm timhoffm reopened this Aug 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

3 participants