anntzer / mplcursors

Interactive data selection cursors for Matplotlib.
https://mplcursors.readthedocs.io
zlib License
114 stars 20 forks source link

Error with imshow and colorbar #59

Closed davidgilbertson closed 1 year ago

davidgilbertson commented 1 year ago

Howdy.

With a heatmap + colorbar, like:

im = ax.imshow(data)
fig.colorbar(im, ax=ax)

Which looks like: image

An error is thrown when hovering over the colorbar.

Last few lines of the error:

  File "/.../mplcursors/_pick_info.py", line 337, in _
    sel = _compute_projection_pick(
  File "/.../mplcursors/_pick_info.py", line 246, in _compute_projection_pick
    vertices[codes == tpath.CLOSEPOLY] = vertices[0]
IndexError: index 0 is out of bounds for axis 0 with size 0

IMO it would be fine to swallow this error and just not show a tooltip (maybe logging.info() the error message?), but I'm sure there's a more elegant way to handle it.

anntzer commented 1 year ago

Thanks for the report. Should now be fixed as of master, can you give it a try?

anntzer commented 1 year ago

Closing per the above.