Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with iPython/Jupyter #48

Open
p-i- opened this issue Nov 10, 2015 · 17 comments
Open

Not working with iPython/Jupyter #48

p-i- opened this issue Nov 10, 2015 · 17 comments

Comments

@p-i-
Copy link

p-i- commented Nov 10, 2015

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 #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)*
@joferkington
Copy link
Owner

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-
Copy link
Author

p-i- commented Nov 10, 2015

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

@joferkington
Copy link
Owner

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- p-i- closed this as completed Nov 10, 2015
@p-i-
Copy link
Author

p-i- commented Nov 10, 2015

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
Copy link
Owner

@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 joferkington reopened this Nov 10, 2015
@p-i-
Copy link
Author

p-i- commented Nov 10, 2015

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
Copy link
Owner

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
#48 (comment)
.

@tacaswell
Copy link

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-
Copy link
Author

p-i- commented Nov 12, 2015

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

@tacaswell
Copy link

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

@p-i-
Copy link
Author

p-i- commented Nov 12, 2015

@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
Copy link
Owner

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-
Copy link
Author

p-i- commented Nov 13, 2015

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
Copy link

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
Copy link

KIC commented Mar 24, 2020

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
Copy link

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

@WDuan-Poppulo
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants