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

[Bug]: Data under cursor crashes on QuadMesh #22334

Open
Stassels opened this issue Jan 27, 2022 · 3 comments
Open

[Bug]: Data under cursor crashes on QuadMesh #22334

Stassels opened this issue Jan 27, 2022 · 3 comments

Comments

@Stassels
Copy link

Bug summary

Matplotlib 3.5.1

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

np.random.seed(19680801)
Z = np.random.rand(10, 10)
x = np.arange(0, 10, 1) 
y = np.arange(10, 20, 1) 

fig, ax = plt.subplots()
qmesh = ax.pcolormesh(x, y, Z)

array_2d = np.random.rand(10,10)
qmesh.set_array(array_2d)

plt.show()

Actual outcome

When I set array to QuadMesh collection and mouse over the image, this error log is produced

Traceback (most recent call last):
File "/home/simons/sdat/lib/python3.9/site-packages/matplotlib/cbook/init.py", line 287, in process
func(*args, **kwargs)
File "/home/simons/sdat/lib/python3.9/site-packages/matplotlib/backend_bases.py", line 3061, in mouse_move
s = self._mouse_event_to_message(event)
File "/home/simons/sdat/lib/python3.9/site-packages/matplotlib/backend_bases.py", line 3051, in _mouse_event_to_message
data = a.get_cursor_data(event)
File "/home/simons/sdat/lib/python3.9/site-packages/matplotlib/collections.py", line 2214, in get_cursor_data
return self.get_array()[ind]
File "/home/simons/sdat/lib/python3.9/site-packages/numpy/ma/core.py", line 3220, in getitem
dout = self.data[indx]
IndexError: index 98 is out of bounds for axis 0 with size 10

Expected outcome

Additional information

This happend only when i set_array to existing QuadMesh.

Operating system

Ubunto 20.04

Matplotlib Version

3.5.1

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

No response

@Stassels Stassels changed the title [Bug]: [Bug]: Data under cursor crashes on QuadMesh Jan 27, 2022
@jklymak
Copy link
Member

jklymak commented Jan 27, 2022

Weird, I can reproduce on master...

@greglucas
Copy link
Contributor

I can't reproduce this on main because that section of code is now turned off by default I think. The underlying issue here is that the set_array() call doesn't flatten the array, but the initial pcolormesh(z) does. qmesh.get_array().shape is different between the two cases.

@anntzer
Copy link
Contributor

anntzer commented Jan 27, 2022

I think quadmesh should only support 2D params to set_array; this would be consistent with what's done in the constructor for coords (the old API, where coords is flattened, is likewise being deprecated right now); this would avoid these kinds of issues. Or at least, we should internally store the array as 2D. But @tacaswell didn't really like that in https://github.com/matplotlib/matplotlib/pull/16908/files#r399894236...

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

6 participants