anntzer / mplcursors

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

It doesn't work if axes.set_xticklabels() is used #32

Closed saurabh3679 closed 3 years ago

saurabh3679 commented 3 years ago

I have found that module doesn't function as it should if axes.set_xticklabels() or axes.set_yticklabels() is used in the code.

anntzer commented 3 years ago

Please clarify what you mean.

saurabh3679 commented 3 years ago

If we assign some labels to the ticks on any axis x or y, cursor functionality stops. Try running this code:

import matplotlib.pyplot as plt
import numpy as np
import mplcursors

x = list(np.arange(0,10,1))
y = list(np.arange(11,21,1))

fig, ax = plt.subplots()
lines = ax.plot(x,y)
ax.set_title("Click somewhere on a line.\nRight-click to deselect.\n"
             "Annotations can be dragged.")

ax.set_xticklabels(['a','b','c','d','e','f','g','h','i','j'])

mplcursors.cursor(lines) # or just mplcursors.cursor()
plt.show()
anntzer commented 3 years ago

This has the same root cause as https://github.com/matplotlib/matplotlib/issues/18727 (mplcursors uses the cursoring mechanism to generate the label). Please comment on that issue if you have a suggestion. Alternatively, you can always manually set the label text.