interact + plotting with ipywidgets 6.0.0 produces many graphs or none
See original GitHub issueThe 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:
- Created 7 years ago
- Comments:26 (16 by maintainers)

Top Related StackOverflow Question
@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:It sounds like we’ve solved this issue - the inline backend won’t work now for interacts, but we should directly use
plt.showinstead, so let’s close this issue and open others for other issues.Thanks again @mglerner for reporting this!