mpldatacursor: Not working with iPython/Jupyter

Python 3.5.0 |Anaconda 2.4.0 (x86_64)| (default, Oct 20 2015, 14:39:26) [GCC 4.2.1 (Apple Inc. build 5577)]

I tried the first code example in a Jupyter/iPython notebook cell:

import matplotlib.pyplot as plt
import numpy as np
from mpldatacursor import datacursor

data = np.outer(range(10), range(1, 5))

fig, ax = plt.subplots()
lines = ax.plot(data)
ax.set_title('Click somewhere on a line')

datacursor(lines)

plt.show()

I’ve run pip install mpldatacursor and done kernel -> restart from Jupyter notebook.

Executing the cell, the plot displays correctly but it is noninteractive. Clicking a line does not do anything.

EDIT: just found https://github.com/joferkington/mpldatacursor/issues/12

Adding %matplotlib nbagg does produce something working, although it gives the error:

/Users/pi/anaconda/lib/python3.5/site-packages/IPython/kernel/init.py:13: ShimWarning: The IPython.kernel package has been deprecated. You should import from ipykernel or jupyter_client instead.

  • “You should import from ipykernel or jupyter_client instead.”, ShimWarning)*

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

What backend are you using?

You’ll have to use %matplotlib nbagg to have interactive figures in an IPython notebook.

Otherwise, the inline backend generates static .png’s. There’s no way for any interaction to happen with the the inline backned.

PS Could this %matplotlib nbagg information be provided in the main readme, under the setup section? A lot of iPython/Jupyter users out there now…