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

[ENH]: matplotlib.widgets.PolygonSelector widget initial cursor position at data rather than (0,0) #28220

Open
rtrwalker opened this issue May 13, 2024 · 6 comments

Comments

@rtrwalker
Copy link
Contributor

Problem

I'm trying this demo of matplotlib.widgets.PolygonSelector widget: Select indices from a collection using polygon selector. The demo as is, is fine because the data is close to (0,0). However, if the data is not near the origin (e.g. add 500 to grid_x and grid_y in the demo) then the PolygonSelector cursor starts at (0,0) when the figure appears and the data is far off and appears small so I have to always zoom in before selecting points. It would be nice if the initial cursor position was relevant to the data.

Proposed solution

In the PolygonSelector widget init method replace:
self._xs, self._ys = [0], [0]
with
self._xs, self._ys = [sum(ax.get_xlim()) / 2], [sum(ax.get_ylim()) / 2
Then the cursor will be in the middle of the axes object that is past to the PolygonSelector initiator.

@timhoffm
Copy link
Member

👍 Do you want to make a pull request?

@Kaustbh
Copy link

Kaustbh commented May 19, 2024

Hi, can I make a PR?

@tacaswell
Copy link
Member

@Kaustbh please do.

@Kaustbh
Copy link

Kaustbh commented Jun 1, 2024

@rtrwalker can you please tell me how to reproduce the problem, I am not able to reproduce it.

@rtrwalker
Copy link
Contributor Author

@Kaustbh copy the example code from Select indices from a collection using polygon selector . Add 500 (or some large number) to grid_x and grid_y .

if __name__ == '__main__':
    import matplotlib.pyplot as plt

    fig, ax = plt.subplots()
    grid_size = 5
    grid_x = np.tile(np.arange(grid_size), grid_size)+500
    grid_y = np.repeat(np.arange(grid_size), grid_size)+500

image

@Kaustbh
Copy link

Kaustbh commented Jun 3, 2024

Its giving me output like this,
version = 3.9.0
backend = "QtAgg"
polygon_selector

what is your matplotlib version ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants