I started writing a question but I ended up solving my issue. Leaving here for others.
Solution: I didn’t need to call pn.pane.Matplotlib
but could simply pass the function to pn.panel
import matplotlib.pyplot as plt
import pandas as pd
import panel as pn
df = pd.DataFrame({"a": [0, 0, 1, 1], "b": [0, 1, 3, 2]})
a = pn.widgets.Select(name="a:", options=[0, 1]).servable()
@pn.depends(a=a)
def plot(a):
s = df[df["a"] == a]["b"]
fig, ax = plt.subplots()
s.plot(ax=ax)
return fig
pn.panel(plot).servable()
Other reference material: