-
-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Matplotlib Pan and Zoom only works for first instance - Not multiple and across sessions #2353
Comments
Thanks @nghenzi . I can confirm that. Also to get the buttons look nice you need to add font awesome css. import panel as pn
pn.extension()
import numpy as np
from matplotlib.figure import Figure
from matplotlib import cm
from matplotlib.backends.backend_agg import FigureCanvas # not needed for mpl >= 3.1
FONTAWESOME_LINK = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.css"
pn.config.css_files.append(FONTAWESOME_LINK)
pn.extension(sizing_mode="stretch_width")
Y, X = np.mgrid[-3:3:100j, -3:3:100j]
U = -1 - X**2 + Y
V = 1 + X - Y**2
speed = np.sqrt(U*U + V*V)
fig0 = Figure(figsize=(8, 6))
ax0 = fig0.subplots()
FigureCanvas(fig0) # not needed for mpl >= 3.1
strm = ax0.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=cm.autumn)
fig0.colorbar(strm.lines)
mpl_pane = pn.pane.Matplotlib(fig0, dpi=144, interactive=True)
mpl_pane.servable() |
Unfortunately the interactivity is still not working. I cannot pan or zoom. matplotlib_not_working.mp4 |
matplotlib_not_working_2nd.mp4import panel as pn
pn.extension()
import numpy as np
from matplotlib.figure import Figure
from matplotlib import cm
from matplotlib.backends.backend_agg import FigureCanvasAgg # not needed for mpl >= 3.1
import matplotlib
FONTAWESOME_LINK = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.css"
pn.config.css_files.append(FONTAWESOME_LINK)
pn.extension(sizing_mode="stretch_width")
def get_mpl():
Y, X = np.mgrid[-3:3:100j, -3:3:100j]
U = -1 - X**2 + Y
V = 1 + X - Y**2
speed = np.sqrt(U*U + V*V)
fig0 = Figure(figsize=(8, 6))
ax0 = fig0.subplots()
# FigureCanvasAgg(fig0) # not needed for mpl >= 3.1
strm = ax0.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=cm.autumn)
fig0.colorbar(strm.lines)
return pn.pane.Matplotlib(fig0, dpi=144, interactive=True)
get_mpl().servable() |
I tried subscribing to click events as described here def onclick(event):
print('%s click: button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %
('double' if event.dblclick else 'single', event.button,
event.x, event.y, event.xdata, event.ydata))
cid = fig0.canvas.mpl_connect('button_press_event', onclick) But unfortunately it did not print anything. |
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I set
interactive=True
in the example in the Reference Gallery https://panel.holoviz.org/reference/panes/Matplotlib.htmlThe plot looks like below and there are errors in the console.
Additional Context
There are some requests for interactive matplotlib. I.e. adding events. C.f. #2349. The question is if the current IPyWidgets based implementation should be fixed or a True Panel version of the interactive Matplotlib should be implemented?
The text was updated successfully, but these errors were encountered: