mpldatacursor icon indicating copy to clipboard operation
mpldatacursor copied to clipboard

Not working with iPython/Jupyter

Open p-i- opened this issue 9 years ago • 17 comments

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)*

p-i- avatar Nov 10 '15 18:11 p-i-

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.

joferkington avatar Nov 10 '15 18:11 joferkington

Sorry, I just found the relevant issue. I've updated the above report.

p-i- avatar Nov 10 '15 18:11 p-i-

To maintain compatibility with older versions of IPython, matplotlib's nbagg backend has to use mechanisms that are depreciated in the latest versions of IPython. Therefore, you're seeing a warning related to that.

It's unavoidable, but can be safely ignored.

joferkington avatar Nov 10 '15 18:11 joferkington

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...

p-i- avatar Nov 10 '15 19:11 p-i-

@p-i-: That's a good point! I'll add it to the readme tonight.

I'm going to re-open this issue as a reminder to myself.

joferkington avatar Nov 10 '15 19:11 joferkington

Not sure whether to open a new issue for this. For my imshow I'm getting x,y readout. But not the value. And the readout is to the bottom right outside of the image. It doesn't look at all similar to the images in the readme.

pi- 2015-11-10 at 23 08 29

I like the readout to be here, but how to get the value? That's what I really need!

PS also clicking has no effect.

p-i- avatar Nov 10 '15 23:11 p-i-

The readout you're seeing is the standard matplotlib readout, not mpldatacursor's.

Did you click on the plot and not get an annotation popping up? If so, I'm a bit stumped. Try removing the display='single', maybe...

On Tue, Nov 10, 2015 at 5:10 PM, Pi [email protected] wrote:

Not sure whether to open a new issue for this. For my imshow I'm getting x,y readout. But not the value. And the readout is to the bottom right outside of the image. It doesn't look at all similar to the images in the readme.

[image: pi- 2015-11-10 at 23 08 29] https://cloud.githubusercontent.com/assets/693495/11078825/195d5718-8800-11e5-8537-1d4810dea8bd.jpg

I like the readout to be here, but how to get the value? That's what I really need!

— Reply to this email directly or view it on GitHub https://github.com/joferkington/mpldatacursor/issues/48#issuecomment-155597120 .

joferkington avatar Nov 11 '15 03:11 joferkington

What version of mpl are you using? There is a strange mix of the new color map and old styling of the nbagg close button.

tacaswell avatar Nov 12 '15 16:11 tacaswell

@tacaswell, mpl 1.4.3 -- I manually copied across Viridis from https://github.com/BIDS/colormap/blob/master/colormaps.py

p-i- avatar Nov 12 '15 16:11 p-i-

You really should not copy code around ad-hoc like that, it leads to a reproducibility nightmare.

tacaswell avatar Nov 12 '15 17:11 tacaswell

@tacaswell, I haven't yet got round to supplying a reproducible problem. But maybe now is the right time.

cursor

(I can't catch the mouse cursor in the screenshot)

%matplotlib nbagg

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

data = np.array([1,2,3])

fig, ax = plt.subplots()
im_ax = ax.imshow( np.array([ data ]) )
datacursor(im_ax)
plt.show()

p-i- avatar Nov 12 '15 19:11 p-i-

That exact example works fine for me on mpl 1.5.0 and IPython 4.0.0, at least on Linux. I can't try it on Windows or OSX, at the moment.

Maybe there's an OSX-specific problem?

snapshot1

joferkington avatar Nov 13 '15 20:11 joferkington

I am on:

Python 3.5.0
Anaconda 2.4.0 (x86_64)| (default, Oct 20 2015, 14:39:26) 
IPython 4.0.0

OSX 10.11.1 (15B42)

My setup could probably be replicated by using a fresh Anaconda installation (I only installed anaconda under a week ago)

p-i- avatar Nov 13 '15 21:11 p-i-

I just submitted matplotlib/matplotlib#6030 which fixes an issue with the datacursor for me in matplotlib 1.5.1 with mpldatacursor 0.6.2

jenshnielsen avatar Feb 19 '16 16:02 jenshnielsen

I have rendering issues using the nbagg backend. However I have thought of making a html image map and use plain javascript to add/render divs. I would actually like to interact between two charts, meaning clicking on one changes the other. This could be done by using the notebook kernel as demonstrated in this gist. Here one could either render a tooltip (or anything using plain javascript) or execute any arbitrary python code i.e. like interactive ipywidgets are doing.

Since I am working heavily on my own open source module I have priorities and can't promise anything. But if I have some time I would appreciate a hint if I could produce such an image map using existing functionality of mpldatacursor and where I should start looking at / hooking into.

KIC avatar Mar 24 '20 14:03 KIC

%matplotlib nbagg did not work with jupyter-lab for me, I had to use %matplotlib widget (requires installing it and nodejs)

banderlog avatar May 29 '20 11:05 banderlog

@p-i- Not sure if you have resolved the problem. I am using mplcursors instead and it works for me on OSX. Screenshot 2021-09-15 at 13 00 24

WDuan-Poppulo avatar Sep 15 '21 12:09 WDuan-Poppulo