The Python Panel library recommends using Bokeh for plotting, but some statistical figures are lacking from the Bokeh package. I want to use matplotlib (or maybe seaborn) to create figures that I can place in panel.Tabs.
For example, the following code works but uses Bokeh instead of matplotlib:
import panel as pn
from bokeh.plotting import figure
p1 = figure(width=400, height=400, name="Line 1")
p1.line([1, 2, 3], [1, 2, 3])
p2 = figure(width=400, height=400, name='Line 2')
p2.line([0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 2, 1, 0])
pn.Tabs(p1, p2)
This (correctly) shows:
However, every attempt I made to show an image from matplotlib failed. Something like p1 = plt.plot(df['wage'])
simply does not work.
Holoviz Panel uses the concept of panes to render figures (plotly figures, bokeh figures, matplotlib figures)... For example, to render a matplotlib figure you have to use
pn.pane.Matplotlib
(here is its documentation).Note that it requires the figure to be created with
matplotlib.figure.Figure
instead of the more traditionalplt.figure
.