Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Plot disappears after updating its data for the second time in Jupiter Notebook #15076

Copy link
Copy link
@dhaitz

Description

@dhaitz
Issue body actions

Bug report

Plot is created and can be updated via a widget, but disappears after the second time the object data is modified.

To properly place the figure within a GridSpec layout, interactive mode is turned off and the figure is not created until the widget's associated function is first called.

Code for reproduction

import ipywidgets as widgets
import matplotlib.pyplot as plt
import numpy as np

%matplotlib widget
# or %matplotlib notebook

plt.ioff()

figures = {}

fig, ax = plt.subplots()

def update_plot(value):
    x, y = np.random.random(10), np.random.random(10)
    l = [_ for _ in zip(x, y)]
    
    if len(ax.lines) == 0:  # first call to function
        ax.plot(x,y)
        plt.show()
        
    else:  # all following calls
        ax.lines[0].set_xdata(x)
        ax.lines[0].set_ydata(y)
        fig.canvas.draw_idle()
        
my_widget = widgets.FloatSlider(min=0.1, max=0.9, step=0.1, value=0.5)

my_widget_box = widgets.interactive(update_plot, value=my_widget)
grid = widgets.GridspecLayout(2, 2, layout=widgets.Layout(justify_content='center'))
grid[0, 0] = my_widget_box

display(grid)

Actual outcome
mpl

Expected outcome

Figure does not disappear

Matplotlib version

  • Operating system: macOs
  • Matplotlib version: 3.1.1.
  • Matplotlib backend (print(matplotlib.get_backend())): "module://ipympl.backend_nbagg" (%matplotlib widget) or "nbAgg" (%matplotlib notebook)
  • Python version: 3.7.4
  • Jupyter version (if applicable): 1.0.0
  • Other libraries: ipywidgets==7.5.1, ipympl==0.3.3,
  • Browser: tested in Safari and Firefox

Installed via brew and pip

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    GUI: nbaggstatus: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.Issues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github ActionMarked by the “Stale” Github Action

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.