Skip to content

Events break in jupyter notebook when calling clear_output() #19057

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

Closed
aph42 opened this issue Dec 2, 2020 · 7 comments
Closed

Events break in jupyter notebook when calling clear_output() #19057

aph42 opened this issue Dec 2, 2020 · 7 comments

Comments

@aph42
Copy link

aph42 commented Dec 2, 2020

Bug report

Bug summary

As of matplotlib version 3.3.2, calling IPython.display.clear_output() in a jupyter notebook seems to break the matplotlib figure event handler system. It seems to be a problem with the interaction between the jupyter notebook widget display system and the matplotlib event system, but reverting to matplotlib 3.3.1 corrects the issue.

Code for reproduction

In a jupyter notebook:

# Paste your code here

%matplotlib notebook

from matplotlib import pyplot as plt
import IPython
import ipywidgets as wdg

wOut = wdg.Output()

def onClick(event):
    with wOut:
        IPython.display.clear_output()
        print(event)

fig, ax = plt.subplots(1,1)
eventid = fig.canvas.mpl_connect('button_press_event', onClick)

IPython.display.display(wOut)

Actual outcome

Clicking on the plot once updates the text in the Output widget, further clicks do nothing.

Further events result in error messages from the jupyter server:

# If applicable, paste the console output here

[IPKernelApp] WARNING | No such comm: 565a2c88b5ff42b08d89aa4cecd34763

Expected outcome

Each time you click on the plot the text in the Output widget should be updated with details of the event.

This code works in version 3.3.1, but not in 3.3.2.

  • Operating system: Ubuntu
  • Matplotlib version: 3.3.2
  • Matplotlib backend (print(matplotlib.get_backend())): nbAgg
  • Python version: 3.7.9
  • Jupyter version (if applicable): 6.1.4
  • Other libraries: IPython 7.19.0

conda

default channel

@jklymak
Copy link
Member

jklymak commented Dec 2, 2020

I can't get this to do anything in any version of matplotlib. The output region just say "Output()" for me no matter what version I try. Are you sure this isn't an ipython/ipywidgets/jupyter interaction problem?

@aph42
Copy link
Author

aph42 commented Dec 2, 2020

Here is what it looks like on my system:

image

The text at the bottom should update at each click. As I said - the code works in 3.3.2, but not in 3.3.1, so I think something has changed on the matplotlib end of things.

@jklymak
Copy link
Member

jklymak commented Dec 2, 2020

But did any of the other libraries change when you changed from 3.3.1 to 3.3.2? So far as I can tell the onClick event fires, but the with wOut doesn't connect... But my understanding of jupyter widgets is pretty minimal.

I'm not saying matplotlib didn't break this, but with my jupyter (6.1.6) and ipython (7.16.1) I can't reproduce the "Expected" behaviour, regardless of Matplotlib version.

@aph42
Copy link
Author

aph42 commented Dec 2, 2020

Thanks for your efforts on this.

Here are the packages in my conda environments that I'm using at the moment:
mpl-3.3.1.packages.txt
mpl-3.3.2.packages.txt

The only differences are in the versions of matplotlib and matplotlib-base.

My first thought was that it was a jupyter/ipython issue, but starting from matplotlib 3.3.2 I have not been able to get it to work with any version of jupyter or ipython that I tried, while starting with matplotlib 3.3.1 it's worked with all versions of jupyter and ipython that i've tried. I will try now a set up with matplotlib 3.3.1, jupyter 6.1.6 and ipython 7.16.1 to see if it works for me.

I can also confirm that before the most recent update, this code was working in a range of different browsers and operating systems.

@aph42
Copy link
Author

aph42 commented Dec 2, 2020

I've tried again with the following conda packages (including matplotlib 3.3.1, jupyter 6.1.6 and ipython 7.16.1):
mpl-3.3.2.jupyter-6.1.6.ipython.7.16.1.packages.txt

On my system (Ubuntu 20.04.1 LTS, firefox 83.0 (64-bit)), it works as expected in that clicking the plot updates the text.

@QuLogic
Copy link
Member

QuLogic commented Dec 3, 2020

Looks like #18638, which would be fixed in 3.3.3. Please try the latest version.

@aph42
Copy link
Author

aph42 commented Dec 3, 2020

Yes - installing 3.3.3 from conda-forge fixed the problem. Thanks.

@aph42 aph42 closed this as completed Dec 3, 2020
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

3 participants