jupyterlab interactive plot

后端 未结 5 1543
Happy的楠姐
Happy的楠姐 2020-11-29 18:33

I\'m getting into using Jupyterlab from Jupyter notebooks. In notebooks I used to use:

import matplotlib.pyplot as plt
%matplotlib notebook
plt.figure()
x =          


        
相关标签:
5条回答
  • 2020-11-29 18:48

    I just solved same problem, by using Chrome Browser instead of Microsoft Edge.

    0 讨论(0)
  • 2020-11-29 18:52

    This solution works in jupyterlab

    import numpy as np
    import matplotlib.pyplot as plt
    from IPython.display import clear_output
    
    
    n = 10
    a = np.zeros((n, n))
    plt.figure()
    
    for i in range(n):
        plt.imshow(a)
        plt.show()
        a[i, i] = 1
        clear_output(wait=True)
    
    0 讨论(0)
  • 2020-11-29 18:53

    To enable the jupyter-matplotlib backend, use the matplotlib Jupyter magic:

    %matplotlib widget
    import matplotlib.pyplot as plt
    plt.figure()
    x = [1,2,3]
    y = [4,5,6]
    plt.plot(x,y)
    

    More info here jupyter-matplotlib on GitHub

    0 讨论(0)
  • 2020-11-29 18:59

    As per Georgy's suggestion, this was caused by Node.js not being installed.

    0 讨论(0)
  • 2020-11-29 19:13

    Complete steps

    1. Install nodejs, e.g. conda install nodejs.
    2. Install ipympl, e.g. pip install ipympl.
    3. [Optional, but recommended; update JupyterLab, e.g.
      pip install --upgrade jupyterlab.]
    4. [Optional, but recommended; for a local user installation, run:
      export JUPYTERLAB_DIR="$HOME/.local/share/jupyter/lab".]
    5. Install extensions:

      jupyter labextension install @jupyter-widgets/jupyterlab-manager
      jupyter labextension install jupyter-matplotlib
      
    6. Enable widgets: jupyter nbextension enable --py widgetsnbextension.

    7. Restart JupyterLab.
    8. Decorate with %matplotlib widget.

    Not recommended, but to blindly get the widget extension working in Anaconda, you can run the following in a terminal window:

    conda install -y nodejs
    pip install ipympl
    pip install --upgrade jupyterlab
    jupyter labextension install @jupyter-widgets/jupyterlab-manager
    jupyter labextension install jupyter-matplotlib
    jupyter nbextension enable --py widgetsnbextension
    
    0 讨论(0)
提交回复
热议问题