Search code examples
pythonmatplotlibjupyterjupyter-labipywidgets

matplotlib widget with ipywidgets in JupyterLab Desktop


I have issues when using %matplotlib widget in JupyterLab Desktop

First: When I run a df.plot() once, it works well, I can see the graph and the cursor, but when I run it again I only got <Axes: >.

Secondly: When I run a widgets.interact(), results are shown in my log files (and so without a cursor).

I tried out = widgets.Output(layout={'border': '1px solid black'})

and with out: display(widgets.VBox([widgets.GridBox(test.children[:nnn-4], layout=widgets.Layout(grid_template_columns="repeat(5, auto)")), test.children[nnn-4], test.children[nnn-3], test.children[nnn-2], test.children[nnn-1]] ))

The Vbox is shown correctly but the graph is still in my logs instead of my regular panel.

Is there a way to fix that?


Solution

  • I used to have a similar problem that figure is draw in console instead of output panel. In my case this issue can be fixed by

    plot = df.plot()
    fig = plot.figure
    fig.canvas.draw()
    fig.canvas.flush_events()
    

    I think you can get some help from this document: Interactive figures