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 notebook" not working in jupyter notebook #4056

Closed
Bipul-Harsh opened this issue Dec 1, 2020 · 8 comments
Closed

"%matplotlib notebook" not working in jupyter notebook #4056

Bipul-Harsh opened this issue Dec 1, 2020 · 8 comments
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@Bipul-Harsh
Copy link

Bipul-Harsh commented Dec 1, 2020

Environment data

  • VS Code version: 1.51.1
  • Jupyter Extension version (available under the Extensions sidebar): v2020.11.392013122
  • Python Extension version (available under the Extensions sidebar): 3.8.6
  • OS (Windows | Mac | Linux distro) and version: Windows 10 20H2
  • Python and/or Anaconda version: 3.8.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): XXX
  • Jupyter server running: Local | Remote | N/A

Expected behaviour

Should show interactive window

Actual behaviour

Error Reporting:
ReferenceError: IPython is not defined

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. Install Python extension by Microsoft
  2. Open Jupyter notebook (Inside vscode with help of extension)
  3. Type "%matplotlib notebook"
  4. Enter code:
    ##Start
    import numpy as np
    import matplitlib.pyplot as plt
    import matplotlib.animation as animation
    n = 100
    x = np.random.randn(n)

def update(curr):
#check if animation is at the last frame, and if so, stop the animation a
if curr == n:
a.event_source.stop()
plt.cla()
bins = np.arange(-4, 4, 0.5)
plt.hist(x[:curr], bins=bins)
plt.axis([-4,4,0,30])
plt.gca().set_title('Sampling the Normal Distribution')
plt.gca().set_ylabel('Frequency')
plt.gca().set_xlabel('Value')
plt.annotate('n = {}'.format(curr), [3,27])

fig = plt.figure()
a = animation.FuncAnimation(fig, update, interval=100)
##END

Logs

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

XXX

@Bipul-Harsh Bipul-Harsh added the bug Issue identified by VS Code Team member as probable bug label Dec 1, 2020
@Bipul-Harsh
Copy link
Author

Even though its working when creating local server with cmd "jupyter notebook", but not working inside vscode.

@IanMatthewHuff
Copy link
Member

@Bipul-Harsh Sorry about the issue. Pulling your logs here would be the most helpful thing. In VS Code settings set Jupyter->Logging->Level to "debug." Then re-run your scenario. After that copy out the contents of the Output window Jupyter tab. That should have most of the info to help us debug this.

Also, when running your code in VS Code are you using the same environment as you are using when running "jupyter notebook" directly?

@IanMatthewHuff IanMatthewHuff added the info-needed Issue requires more information from poster label Dec 1, 2020
@Bipul-Harsh
Copy link
Author

ReferenceError: IPython is not defined
at eval (eval at runCodeHere (vscode-webview-resource://d1ff7912-58b4-4362-ab14-98502fc11542/file///c%3A/Users/bipul/.vscode/extensions/ms-toolsai.jupyter-2020.11.392013122/out/datascience-ui/notebook/vendorsnteract_transforms.bundle.js:2:12595), :926:1)
at runCodeHere (vscode-webview-resource://d1ff7912-58b4-4362-ab14-98502fc11542/file///c%3A/Users/bipul/.vscode/extensions/ms-toolsai.jupyter-2020.11.392013122/out/datascience-ui/notebook/vendors
nteract_transforms.bundle.js:2:12595)
at t.value (vscode-webview-resource://d1ff7912-58b4-4362-ab14-98502fc11542/file///c%3A/Users/bipul/.vscode/extensions/ms-toolsai.jupyter-2020.11.392013122/out/datascience-ui/notebook/vendors~nteract_transforms.bundle.js:2:13027)
at Ta (vscode-webview-resource://d1ff7912-58b4-4362-ab14-98502fc11542/file///c%3A/Users/bipul/.vscode/extensions/ms-toolsai.jupyter-2020.11.392013122/out/datascience-ui/notebook/commons.initial.bundle.js:2:2398498)
at Pa (vscode-webview-resource://d1ff7912-58b4-4362-ab14-98502fc11542/file///c%3A/Users/bipul/.vscode/extensions/ms-toolsai.jupyter-2020.11.392013122/out/datascience-ui/notebook/commons.initial.bundle.js:2:2401420)
at vscode-webview-resource://d1ff7912-58b4-4362-ab14-98502fc11542/file///c%3A/Users/bipul/.vscode/extensions/ms-toolsai.jupyter-2020.11.392013122/out/datascience-ui/notebook/commons.initial.bundle.js:2:2414498
at Object.t.unstable_runWithPriority (vscode-webview-resource://d1ff7912-58b4-4362-ab14-98502fc11542/file///c%3A/Users/bipul/.vscode/extensions/ms-toolsai.jupyter-2020.11.392013122/out/datascience-ui/notebook/commons.initial.bundle.js:2:25134)
at Ms (vscode-webview-resource://d1ff7912-58b4-4362-ab14-98502fc11542/file///c%3A/Users/bipul/.vscode/extensions/ms-toolsai.jupyter-2020.11.392013122/out/datascience-ui/notebook/commons.initial.bundle.js:2:2414432)
at xs (vscode-webview-resource://d1ff7912-58b4-4362-ab14-98502fc11542/file///c%3A/Users/bipul/.vscode/extensions/ms-toolsai.jupyter-2020.11.392013122/out/datascience-ui/notebook/commons.initial.bundle.js:2:2414208)
at Es (vscode-webview-resource://d1ff7912-58b4-4362-ab14-98502fc11542/file///c%3A/Users/bipul/.vscode/extensions/ms-toolsai.jupyter-2020.11.392013122/out/datascience-ui/notebook/commons.initial.bundle.js:2:2413553)

@Bipul-Harsh
Copy link
Author

This is what actually written in error.

@Bipul-Harsh
Copy link
Author

Regarding the environment both are using the same python3 version installed in my pc. The jupyter notebook I run on cmd opens default web browser for interface while in vscode it with MS python extension it opens within it.

@Bipul-Harsh
Copy link
Author

I think there might be some feature missing in the extension regarding IPython, as regarding normal plotting with matplotlib it didnt didnt give any error, but with Interactive plotting it gives error.

While running on browser offline with local server it works for interactive plotting also, so that could be the issue.

@Bipul-Harsh
Copy link
Author

So, I hope I have provided the info needed

@IanMatthewHuff
Copy link
Member

@Bipul-Harsh Thanks for the info. I poked around a bit more, and found that we don't actually support the notebook mode for matplot lib currently. Seems like you can try using the widget mode instead, which should work as we support IPyWidgets.

#1948

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2021
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 info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants