Matplotlib panel in golden layout

I’m using the golden layout template from the Vtkslicer example. I want to re purpose this layout and put in my own elements. I’d like to put in a matplotlib figure in this layout.
I create one as follows:

fig = plt.figure(figsize=(3, 4))
plt.plot([1,2,3])
mpl = pn.pane.Matplotlib(fig)

But when I substitute a bokeh pane for this matplotlib one, the GUI still loads but none of the layout elements are populated.

Also, and possibly unrelated, when I run the Vtkslider example in a jupyter notebook, I dont get any output, however when I run $ panel serve golden_layout.ipynb it works fine.

Any ideas? The mpl element itself also works perfectly fine in a jupyter notebook.

Using https://panel.holoviz.org/reference/panes/Matplotlib.html#panes-gallery-matplotlib

import matplotlib.pyplot as plt
import matplotlib

matplotlib.use('agg')

fig = plt.figure(figsize=(3, 4))
plt.plot([1,2,3])
mpl = pn.pane.Matplotlib(fig, sizing_mode='stretch_both')
mpl

and replacing all panels in the VTKSlicer template by mpl

tmpl = pn.Template(template=(template % 'server'), nb_template=(template % 'notebook'))
tmpl.nb_template.globals['get_id'] = make_globally_unique_id

tmpl.add_panel('controller', mpl)
tmpl.add_panel('scene3d', mpl)
tmpl.add_panel('slice_i', mpl)
tmpl.add_panel('slice_j', mpl)
tmpl.add_panel('slice_k', mpl)

tmpl.servable(title='VTKSlicer')

I get this:
ezgif.com-video-to-gif (2)

I have the same result in notebook:

I just realized i should be looking in the browser console for errors:

console.trace() Error: "Model 'panel.models.markup.HTML' does not exist. This could be due to a widget or a custom model not being registered before first usage.

So it might be this issue.

I’m on windows using panel 0.9.5 (pyviz channel) and bokeh 2.0.1. I think I’ll wait for a new bokeh release and try again.

Which platform are you on?

1 Like

Windows 10, same as you but I use a dev version of panel and the workaround setting bokeh ressources inline

Do you only need the dev version of panel to do so or also dev version of bokeh?

one solution is downgrade to panel 0.9.4 and bokeh 2.0.0. There is some problem with some js library or module.

if you need the last version, @philippjfr recommended to set a environment variable (BOKEH_RESOURCES=inline), something like this (in a conda environment)

conda env config vars set BOKEH_RESOURCES=inline

Both work!
So I don’t even need to build bokeh myself for that. Cool :slightly_smiling_face:

Worth noting that bokeh 2.0.2 with a fix for this issue will be released tonight.

1 Like