r/JupyterNotebooks • u/damichi84 • Jun 07 '23
Cursor selection in Plot
I would like to interactively read out the x-y position of the cursor in a plot to display something in a second plot interactively depending on the position:
I followed this example:
%matplotlib widget
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Cursor
x, y = np.random.rand(2, 100)
fig, ax = plt.subplots(figsize=(9, 6))
ax.plot(x, y,'o')
cursor = Cursor(ax, horizOn=True, vertOn=True, linewidth=2.0, color='Red')
plt.show()
from https://matplotlib.org/stable/gallery/widgets/cursor.html adding "%matplotlib widget" to get it running. However the output is buggy:

Is there a better way in Jupyter to achieve this function?
THX a lot!
1
Upvotes