You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ipympl 0.8.2 - ginput() does not work on Jupyterlab / returns an empty array #400
Describe the bug
I should be able to select data points from a figure and then red crosses are supposed to appear after clicking with the mouse, but nothing happens, an empty array is returned and the figures only appear after the timeout of ginput().
Expected behavior
Figure pops up and I can click with the mouse on the figure to select data points. An array will be generated
To Reproduce
%matplotlib widget
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(10)
plt.plot(t, np.sin(t))
plt.title('matplotlib.pyplot.ginput()\
function Example', fontweight ="bold")
print("After 3 clicks :")
x = plt.ginput(3)
print(x)
plt.show()
My Platform
Firefox on Arch Linux, latest version after system update.
I tested it on Jupyterlab, I did not test it on Jupyter-notebook.
This runs into a current limitations of ipywidgets (which ipympl is based on) which is that blocking input is impossible. Until that is fixed then ginput will not behave as expected for either ipympl or nbagg.
We should probably at least raise a warning about this but I don't think there's really a safe reasonable way for a backend to reach into pyplot and mess with things (@tacaswell ?)
Activity
ianhi commentedon Nov 27, 2021
This runs into a current limitations of ipywidgets (which ipympl is based on) which is that blocking input is impossible. Until that is fixed then ginput will not behave as expected for either ipympl or nbagg.
We should probably at least raise a warning about this but I don't think there's really a safe reasonable way for a backend to reach into pyplot and mess with things (@tacaswell ?)
As a workaround I suggest building your code around the matplotlib callback system, in particular to make use of the
pick event. For example:https://matplotlib.org/stable/gallery/event_handling/pick_event_demo.html
Or see how
scatter_selectorworks https://github.com/ianhi/mpl-interactions/blob/3d98c9b7f603d12ae082dd2e90c3ee6ae943f874/mpl_interactions/widgets.py#L48