2

The matplotlib figure suddenly doesn't display in vscode's jupyter notebook environment, even though I used:

%matplotlib inline

When I plot a figure, e.g.:

data = np.random.randn(1000, 2)
fig, ax = plt.subplots()
ax.scatter(data[:, 0], data[:, 1])
plt.show()

only return followings:

<Figure size 432x288 with 1 Axes>

Here is the versions:

  • matploltlib: 3.5.1
  • numpy: 1.22.3
  • ipython : 8.1.1
  • vscode: 1.73.1
  • vscode jupyter extension: 2022.9.1303220346

I tried to re-install my vscode and it works, but several days later it happens again.

So if any one knows how to solve it? Thanks!

Nanxi Chen
  • 31
  • 5
  • When I open the same file (even if just open without running) with jupyter notebook instead of the vscode-jupyter-extension, the figures come out. – Nanxi Chen Dec 18 '22 at 11:59
  • Welcome to SO! Could you please check if the discussion from [here](https://github.com/microsoft/vscode-jupyter/issues/9697) helps to resolve the issue? – medium-dimensional Dec 18 '22 at 12:05
  • 1
    Thanks for your answering! I tried to update `ipympl` to 0.9.1, which works in the context of `%matplotlib widget`, but not helps with `%matplotlib inline` context. – Nanxi Chen Dec 18 '22 at 12:30
  • Can you please try once `plt.gcf()` instead of `plt.show()`? I am just guessing here what might work since I don't have VS Code installed in my machine at this moment. – medium-dimensional Dec 18 '22 at 12:40
  • 1
    Two lines of `
    ` come out with `plt.gcf()`. I think the key problem is the renderer, because the Figure object returned succesfully.
    – Nanxi Chen Dec 18 '22 at 12:49
  • Does this answer your question? [Matplotlib plots not showing in VS Code](https://stackoverflow.com/questions/66121948/matplotlib-plots-not-showing-in-vs-code) – Gregor Dec 20 '22 at 12:45

1 Answers1

1

The answer to Matplotlib plots not showing in VS Code? works. I just needed to change the display mode of jupyter renderer.

Michael Delgado
  • 13,789
  • 3
  • 29
  • 54
Nanxi Chen
  • 31
  • 5
  • Could you please add a link of the answer that helped you directly instead of the question link? The linked post contains only 10 answers, so *answer #16* might be confusing for those who are also looking for solutions to a similar problem. – medium-dimensional Dec 19 '22 at 14:08
  • Yes, those are probably votes and not the # of the answer? The votes change and fluctuate, @Nanxi Chen. – Wayne Dec 19 '22 at 20:23