Search code examples
python-3.xjupyter-notebookjupyter-labbqplot

Bqplot in jupyter lab returns a string instead of an (interactive) image


Today I've been trying to install the module bqplot and use jupyter lab for the very first time.

However, I've not been able to obtain the desired output when using the basic examples as shown on their website.

The code I'm trying to execute is as following:

import numpy as np
from bqplot import pyplot as plt

plt.figure(1, title='Line Chart')
np.random.seed(0)
n = 200
x = np.linspace(0.0, 10.0, n)
y = np.cumsum(np.random.randn(n))
plt.plot(x, y)
plt.show()

After running this code in a jupyter (lab) cell, the given output is:

VBox(children=(Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig…

Whereas in the normal jupyter notebook, the output shows the example image.

I've so far no idea what has gone wrong and would appreciate any help!

Thanks.


Solution

  • I had the same issue and solved it by installing both the bqplot labextension and the @jupyter-widgets/jupyterlab-manager extension:

    jupyter labextension install @jupyter-widgets/jupyterlab-manager
    jupyter labextension install bqplot
    

    After a restart of jupyter lab, the widgets are displayed.

    I guess the misunderstanding lies in the installation instructions of bqplot: It only mentions these steps as "experimental JupyterLab extension", but the installation step for enabling bqplot in Jupter Lab misses them.