Hi Matplotlib Community
I would like to be able to create awesome interactive apps using Matplotlib and HoloViz Panel.
Panel already provides support for matplotlib
via the HoloViz Panel Matplotlib
pane. This can display the matplotlib.figure.Figure
and provides integrations with Ipywidgets.
Now we want to add support for matplotlib event handling and picking.
One issue I don’t know how to solve is that the pan and zoom of matplotlib only works on the first instantation. Not if I refresh the browser window.
The bug is reported here Matplotlib Pan and Zoom only works for first instance - Not multiple and across sessions · Issue #2353 · holoviz/panel (github.com).
I am looking for help. Any suggestions on the cause and/ or solution would be highly appreciated.
Thanks
Reproducible Example
Run this via panel serve name_of_script.py
.
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 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()