You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mpl_connect does not write output to jupyter notebook #6948
Eh, I think it is a bit more complicated than that. I bet if you clicked
enough times, it would show up due to buffered outputs, but I don't know
that for certain. It would help to know what backend you are using for this
example.
Repeated clicks don't help. What do you mean by backend? Please specify what you are interested in (packages/versions/ dunno). I recently started using matplotlib/jupyter so I'm not so well versed in jargon :)
As for repeated clicks, I am betting it would have to be on the order of
about 100 or so clicks to trigger a buffer clear, so unless you clicked
that many times, I still am betting that is the problem.
Repeated clicks don't help. What do you mean by backend? Please specify
what you are interested in (packages/versions/ dunno). I recently started
using matplotlib/jupyter so I'm not so well versed in jargon :)
The problem is that nbagg does not hook into the widget framework (as it existed first 😉 ) and the stdout from the callbacks are not getting set across the com. Pretty sure this is fixed by ipymplhttps://github.com/matplotlib/jupyter-matplotlib
Okay, so I pip installed pip install ipympl
and jupyter nbextension enable --py --sys-prefix ipympl
from the link. When I relaunched the notebook without my custom init, using matplotlib backend: TkAgg, it opens a new window and outputs click events into it. But if I specify magic %matplotlib notebook
it is still the same, no change. And I added the draw_idle, that's nice.
No, interactive backends can not always be changed (we are working to make
that more possible, though). Once pyplot is imported, you can't switch
interactive backends. Our eventual goal is that switching would be possible
until the first figure creation, and ideally that it could be deferred
until the first show() (but that won't be possible for a long time).
There seems to be another issue: I have two notebooks opened now: A and B.
In A, I have %matplotlib tk
In B, I have %matplotlib notebook
If I try to change A: %matplotlib notebook I get
Warning: Cannot change to a different GUI toolkit: notebook. Using tk
instead.
If I try to change B: %matplotlib tk I get
Warning: Cannot change to a different GUI toolkit: tk. Using notebook
instead.
Changing to inline works fine. I thought these can be changed dynamically?
Thanks. After about an hour of shuffling around imports, restarting kernels etc. I was able to come up with this:
Also, the correct order for the imports is:
# standard imports
import ipympl
import matplotlib.pyplot as plt
import matplotlib
from pylab import *
# other bunch of things I use
import math
import random
from tqdm import tqdm
import logging
import numpy as np
import pandas as pd
So, currently the backend is: Using matplotlib backend: TkAgg
However as you can see on the uploded img, it doesn't integrate that well with jupyter ntb... but I get the output there, and it also has export button, which is a nice feature.
I think it would be better to have this somewhere documented, because I wonder how I would come up with this without submitting the issue. I'd like to add it somewhere, but I'm not sure where, since I don't know your ecosystem that well...
I strongly urge against the usage of pylab. At the very least, it doesn't
make sense to mix pylab and pyplot. Use one or the other -- I recommend
pyplot because "star imports" are risky (and did you know that it messes up
python's min()/max()?)
Also, the import matplotlib should come before import matplotlib.pyplot, as it would allow one to take certain actions such as
selecting backend prior to committing to it by importing pyplot.
As for documenting this, I still think there is some other problem going on
here that is complicating things. The difficulties you are encountering
doesn't seem to be normal and I wonder if something else causing problems.
IPYMPL is not documented because it's very early alpha state. Which should be indicated by the readme and the fact that it is V 0.0.2 but it will be better documented in the future once it is ready to use.
The existing notebook backend within matplotlib has some bugs and limitations where this is probably one of them we may be able to fix this bug there in the mean time until ipympl is ready
The set_dpi warning is probably only happing when using this on retina and other hidp monitors and is fixed by backporting #5383 for me (via #6956 ). I could not reproduce it originally on a regular dpi monitor.
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
WeatherGod commentedon Aug 15, 2016
Eh, I think it is a bit more complicated than that. I bet if you clicked
enough times, it would show up due to buffered outputs, but I don't know
that for certain. It would help to know what backend you are using for this
example.
On Mon, Aug 15, 2016 at 4:29 PM, michalsustr notifications@github.com
wrote:
michalsustr commentedon Aug 15, 2016
Repeated clicks don't help. What do you mean by backend? Please specify what you are interested in (packages/versions/ dunno). I recently started using matplotlib/jupyter so I'm not so well versed in jargon :)
WeatherGod commentedon Aug 15, 2016
what is returned by the following cell:
import matplotlib
matplotlib.get_backend()
As for repeated clicks, I am betting it would have to be on the order of
about 100 or so clicks to trigger a buffer clear, so unless you clicked
that many times, I still am betting that is the problem.
On Mon, Aug 15, 2016 at 5:10 PM, michalsustr notifications@github.com
wrote:
michalsustr commentedon Aug 16, 2016
it uses 'nbAgg'
That's what I would call a bug :) I'm quite confident it's over 100. https://imgur.com/a/bzCSJ
tacaswell commentedon Aug 16, 2016
The problem is that nbagg does not hook into the widget framework (as it existed first 😉 ) and the stdout from the callbacks are not getting set across the com. Pretty sure this is fixed by
ipymplhttps://github.com/matplotlib/jupyter-matplotlibtacaswell commentedon Aug 16, 2016
You should also use
draw_idleinstead ofdrawmichalsustr commentedon Aug 16, 2016
Okay, so I pip installed
pip install ipympland
jupyter nbextension enable --py --sys-prefix ipymplfrom the link. When I relaunched the notebook without my custom init, using matplotlib backend: TkAgg, it opens a new window and outputs click events into it. But if I specify magic
%matplotlib notebookit is still the same, no change. And I added the
draw_idle, that's nice.michalsustr commentedon Aug 16, 2016
There seems to be another issue: I have two notebooks opened now: A and B.
In A, I have %matplotlib tk
In B, I have %matplotlib notebook
If I try to change A: %matplotlib notebook I get
If I try to change B: %matplotlib tk I get
Changing to
inlineworks fine. I thought these can be changed dynamically?jenshnielsen commentedon Aug 16, 2016
Matplotlib has never supported changing the backend in an running session. You will need to restart the notebook to change backend.
I don't think
%matplotlib notebookloads the newipymplbackend yet. You will need to use it as described in https://github.com/matplotlib/jupyter-matplotlib/blob/master/examples/ipympl.ipynb that should probably be fixed but I think the fix needs to go into IPython where the % magics are definedWeatherGod commentedon Aug 16, 2016
No, interactive backends can not always be changed (we are working to make
that more possible, though). Once pyplot is imported, you can't switch
interactive backends. Our eventual goal is that switching would be possible
until the first figure creation, and ideally that it could be deferred
until the first show() (but that won't be possible for a long time).
On Tue, Aug 16, 2016 at 11:21 AM, michalsustr notifications@github.com
wrote:
michalsustr commentedon Aug 16, 2016
Thanks. After about an hour of shuffling around imports, restarting kernels etc. I was able to come up with this:
Also, the correct order for the imports is:
So, currently the backend is:
Using matplotlib backend: TkAggHowever as you can see on the uploded img, it doesn't integrate that well with jupyter ntb... but I get the output there, and it also has export button, which is a nice feature.
I think it would be better to have this somewhere documented, because I wonder how I would come up with this without submitting the issue. I'd like to add it somewhere, but I'm not sure where, since I don't know your ecosystem that well...
michalsustr commentedon Aug 16, 2016
And I almost forgot, there was that unhandled UserWarning...
WeatherGod commentedon Aug 16, 2016
I strongly urge against the usage of pylab. At the very least, it doesn't
make sense to mix pylab and pyplot. Use one or the other -- I recommend
pyplot because "star imports" are risky (and did you know that it messes up
python's min()/max()?)
Also, the
import matplotlibshould come beforeimport matplotlib.pyplot, as it would allow one to take certain actions such asselecting backend prior to committing to it by importing pyplot.
As for documenting this, I still think there is some other problem going on
here that is complicating things. The difficulties you are encountering
doesn't seem to be normal and I wonder if something else causing problems.
On Tue, Aug 16, 2016 at 12:05 PM, michalsustr notifications@github.com
wrote:
jenshnielsen commentedon Aug 16, 2016
IPYMPL is not documented because it's very early alpha state. Which should be indicated by the readme and the fact that it is V 0.0.2 but it will be better documented in the future once it is ready to use.
The existing notebook backend within matplotlib has some bugs and limitations where this is probably one of them we may be able to fix this bug there in the mean time until ipympl is ready
That being said I cannot reproduce either of your issues with ipympl
https://gist.github.com/jenshnielsen/6af81090e8d243c3ea2926abef77b19f
jenshnielsen commentedon Aug 18, 2016
The set_dpi warning is probably only happing when using this on retina and other hidp monitors and is fixed by backporting #5383 for me (via #6956 ). I could not reproduce it originally on a regular dpi monitor.
jenshnielsen commentedon Aug 18, 2016
%matplotlib ipymplis added in ipython/ipython#9885SylvainCorlay commentedon Aug 18, 2016
@michalsustr importing ipympl should switch the backend to ipympl.
github-actions commentedon Oct 9, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!