joferkington / mpldatacursor

Interactive "data cursors" (a.k.a. annotation pop-ups) for matplotlib
MIT License
194 stars 47 forks source link

Not working with iPython/Jupyter #48

Open p-i- opened 8 years ago

p-i- commented 8 years ago

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

joferkington commented 8 years ago

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.

p-i- commented 8 years ago

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

joferkington commented 8 years ago

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.

p-i- commented 8 years ago

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

joferkington commented 8 years ago

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

p-i- commented 8 years ago

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.

joferkington commented 8 years ago

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 notifications@github.com 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 .

tacaswell commented 8 years ago

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.

p-i- commented 8 years ago

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

tacaswell commented 8 years ago

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

p-i- commented 8 years ago

@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()
joferkington commented 8 years ago

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

p-i- commented 8 years ago

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)

jenshnielsen commented 8 years ago

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

KIC commented 4 years ago

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.

banderlog commented 4 years ago

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

WDuan-Poppulo commented 2 years ago

@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