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

Matplotlib callbacks not working on VSCode Jupyter Extension #3987

Closed
dcordb opened this issue Nov 20, 2020 · 4 comments
Closed

Matplotlib callbacks not working on VSCode Jupyter Extension #3987

dcordb opened this issue Nov 20, 2020 · 4 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug ipywidgets Rendering, loading, saving, anything to do with IPyWidgets

Comments

@dcordb
Copy link

dcordb commented Nov 20, 2020

%matplotlib
import matplotlib.pyplot as plt

def onPick(event):
    print('here')
    print(event)

fig, ax = plt.subplots()

ax.scatter([5], [5], s=1000, picker=True)
fig.canvas.mpl_connect('pick_event', onPick)
plt.show()

The above code plots a single point on (5, 5) and adds an event handler to it, so that when the point is clicked it can print info about the clicked point.

If one run this and click the button it should enter on onPick function. In a Jupyter Notebook it works fine, while in VSCode Jupyter Extension doesn't.

Environment data

  • VS Code version: 1.51.1
  • Extension version (available under the Extensions sidebar): v2020.11.371526539
  • Jupyter Extension version (available under the Extensions sidebar): v2020.11.358541065
  • OS (Windows | Mac | Linux distro) and version: Ubuntu 19.10
  • Python and/or Anaconda version: Python 3.8.5
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): pyenv
  • Jupyter server running: Local

Expected behaviour

It should print the event when the point is clicked.

jupyter-ok

Actual behaviour

It doesn't print anything besides the backend selection.

jupyter-wa

Steps to reproduce:

  1. Paste this code on a Jupyter cell of VSCode extension.
  2. Run it.
  3. Click on the point (with left or right click, it doesn't matter).

Logs

Output for Jupyter in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Jupyter)

Started kernel Python 3
> ~/.pyenv/versions/3.8.5/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.11.358541065/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v
> ~/.pyenv/versions/3.8.5/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2020.11.358541065/pythonFiles/pyvsc-run-isolated.py vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_launcher_daemon -v

@dcordb dcordb added the bug Issue identified by VS Code Team member as probable bug label Nov 20, 2020
@dcordb
Copy link
Author

dcordb commented Nov 20, 2020

By the way, if on onPick function we add an artist to the axes instance it adds it and shows it. Only the standard output isn't shown.

import matplotlib.pyplot as plt

def onPick(event):
    print('here')
    print(event)
    ax.text(5, 5, 'Test Text!')
    plt.draw()

fig, ax = plt.subplots()

ax.scatter([5], [5], s=1000, picker=True)
fig.canvas.mpl_connect('pick_event', onPick)
plt.show()

In the above code I added a text to current axes instance, if you click on the point you will see it, so onPick is called.

@DonJayamanne
Copy link
Contributor

I'm sorry for the delay in getting back to you on this issue.
Will be looking into this righ tnow.

@DonJayamanne
Copy link
Contributor

I can confirm this doen't work at our end.
Looks like we need to handle some custom messages.

@DonJayamanne DonJayamanne removed their assignment Feb 13, 2021
@greazer greazer added the ipywidgets Rendering, loading, saving, anything to do with IPyWidgets label Aug 3, 2021
@DonJayamanne
Copy link
Contributor

From what I can tell this is now working in VS Code.
Please feel free to re-open this issue or file an new issue.
I believe this was fixed last month as part of the other IPYWidget issues #9503

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug ipywidgets Rendering, loading, saving, anything to do with IPyWidgets
Projects
None yet
Development

No branches or pull requests

3 participants