question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

interact + plotting with ipywidgets 6.0.0 produces many graphs or none

See original GitHub issue

The following code worked for me in the previous version of ipywidgets (5.whatever-was-most-recent). By “worked” I mean it produced one plot, and dragging the slider updated that plot, with only one line shown on the plot at a time. If relevant, I’m using Chrome on OS X.

import matplotlib.pyplot as plt
%matplotlib inline
from ipywidgets import interact

def f(n):
    plt.plot([0,1,2],[0,1,n])
interact(f,n=(0,10))

I just updated to 6.0.0, cleared my browser cache, and relaunched everything. Now I get a new plot inserted vertically below the old one every time I drag the slider around.

I tried

import matplotlib.pyplot as plt
%matplotlib inline
from ipywidgets import interact

def f(n):
    plt.plot([0,1,2],[0,1,n])
interact(f,n=(0,10))

instead, and the plot does not update when the slider is dragged.

Changing %matplotlib inline to %matplotlib notebook and adding plt.clf() before the plot line sometimes works, but also sometimes just produces a blank plot when I drag the slider around.

Here’s some system information; I’m happy to provide more:

{'commit_hash': '5c9c918',
 'commit_source': 'installation',
 'default_encoding': 'UTF-8',
 'ipython_path': '/Users/mglerner/anaconda3/envs/nodev_up/lib/python3.6/site-packages/IPython',
 'ipython_version': '5.1.0',
 'os_name': 'posix',
 'platform': 'Darwin-15.6.0-x86_64-i386-64bit',
 'sys_executable': '/Users/mglerner/anaconda3/envs/nodev_up/bin/python',
 'sys_platform': 'darwin',
 'sys_version': '3.6.0 |Anaconda custom (x86_64)| (default, Dec 23 2016, '
                '13:19:00) \n'
                '[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]'}

In [2]: matplotlib.__version__ Out[2]: '2.0.0'

I then tried updating a few things to the conda-forge version, including matplotlib. The results of the update are below, but the update did not fix the behavior.

`╰─➤ conda update ipython matplotlib jupyter numpy -c conda-forge 1 ↵ Fetching package metadata … Solving package specifications: .

Package plan for installation in environment /Users/mglerner/anaconda3/envs/nodev_up:

The following NEW packages will be INSTALLED:

blas:         1.1-openblas       conda-forge
libgfortran:  3.0.0-0            conda-forge
olefile:      0.44-py36_0        conda-forge
openblas:     0.2.19-1           conda-forge

The following packages will be UPDATED:

freetype:     2.5.5-2                        --> 2.7-1                              conda-forge
ipython:      5.1.0-py36_1                   --> 5.3.0-py36_0                       conda-forge
libpng:       1.6.27-0                       --> 1.6.28-0                           conda-forge
matplotlib:   2.0.0-np111py36_0              --> 2.0.0-np111py36_2                  conda-forge
numpy:        1.11.3-py36_0                  --> 1.11.3-py36_blas_openblas_200      conda-forge [blas_openblas]
pillow:       4.0.0-py36_0                   --> 4.0.0-py36_2                       conda-forge
scipy:        0.18.1-np111py36_1             --> 0.18.1-np111py36_blas_openblas_201 conda-forge [blas_openblas]

The following packages will be SUPERCEDED by a higher-priority channel:

jupyter:      1.0.0-py36_3                   --> 1.0.0-py36_0                       conda-forge
scikit-learn: 0.18.1-np111py36_1             --> 0.18-np111py36_blas_openblas_203   conda-forge [blas_openblas]

Proceed ([y]/n)? `

After doing so, the behavior was unchanged.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:26 (16 by maintainers)

github_iconTop GitHub Comments

12reactions
jasongroutcommented, Mar 4, 2017

@mglerner - it seems I was mistaken above - you can use %matplotlib inline, but you’ll still need to explicitly show the plot. This works fine:

import matplotlib.pyplot as plt
from ipywidgets import interact
%matplotlib inline

def f(n):
    plt.plot([0,1,2],[0,1,n])
    plt.show()
interact(f,n=(0,10))
1reaction
jasongroutcommented, Mar 2, 2017

It sounds like we’ve solved this issue - the inline backend won’t work now for interacts, but we should directly use plt.show instead, so let’s close this issue and open others for other issues.

Thanks again @mglerner for reporting this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

interact and plotting with ipywidgets events produces many ...
I am trying to use widget events to make an interactive graph. %matplotlib inline import numpy ...
Read more >
ipywidgets Documentation
Question: When I display a widget or interact, I just see some text, such as IntSlider(value=0) or interactive(children=(IntSlider(value=0, ...
Read more >
Ipywidgets with matplotlib - Kapernikov
To get started, we set the ipympl backend, which makes matplotlib plots interactive. We do this using a magic command, starting with %....
Read more >
Interactive data analysis with figurewidget ipywidgets in Python
Let's assign the widgets that we're going to be using in our app. In general all these widgets will be used to filter...
Read more >
Matplotlib Figure Is Not Updating With Ipywidgets Slider
Interactive Data Analysis with FigureWidget ipywidgets in Python With ... interact + plotting with ipywidgets 6.0.0 produces many graphs or none #1179.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found