Skip to content

[Bug]: QuadMesh get_cursor_data errors if no array is set #22908

Closed
@raphaelquast

Description

@raphaelquast

Bug summary

This is just a very minor bug I noticed...

When using a QuadMesh without setting an array, the get_cursor_data function throws an error because it does not check if an array has been set.

This is somewhat connected to #22334 but this is just about the case when no array has been set.

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib.collections import QuadMesh
import numpy as np

x, y = np.linspace([-1.5, -1.5], [1.5, 1.5], 20).T
X, Y = np.meshgrid(x, y)

coll = QuadMesh(np.stack((X, Y), axis=2))
f, ax = plt.subplots()
ax.add_collection(coll)

Actual outcome

TypeError: 'NoneType' object is not subscriptable
Traceback (most recent call last):
  File "...\matplotlib\cbook\__init__.py", line 287, in process
    func(*args, **kwargs)
  File "...\matplotlib\backend_bases.py", line 3061, in mouse_move
    s = self._mouse_event_to_message(event)
  File "...\matplotlib\backend_bases.py", line 3051, in _mouse_event_to_message
    data = a.get_cursor_data(event)
  File "...\matplotlib\collections.py", line 2214, in get_cursor_data
    return self.get_array()[ind]
TypeError: 'NoneType' object is not 

Expected outcome

no error

Additional information

No response

Operating system

No response

Matplotlib Version

3.5.1

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

No response

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