Plt.show() does not plot

Asked 2 years ago, Updated 2 years ago, 57 views

Running Python 3.6.5 in VS Code.The script says import matplotlib.pyplotasplt, but plt.show() also shows the plot window, but nothing is drawn and the window remains completely white.There is no error message.

plt.show() is preceded by various processing and the result is code such as plt.plot(x,y,label="result").It came out when I ran on IDLE before.Now I'm building with Homebrew and Pyenv and putting in VS Code.

Add

The plot does not appear even with simple codes such as:

import numpy as np
import matplotlib.pyplot asplt

# Output line graph
left = np.array ([1, 2, 3, 4, 5])
height = np.array ([100, 300, 200, 500, 400])
plt.plot(left, height)

And the terminal window under VSCode has

/Users/user1/Desktop; env "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1"/Users/user1/.pyenv/versions/3.6.5/bin/python/Users/user1/.vscode/extensions/messon.python.psycho/psycho/psycho/mys-psycho-psycho-pers.pers.pys.pys.pys.pys.pys.pys.pys.pys.pys

appears.

Please let me know what caused it.

python matplotlib

2022-09-29 22:12

1 Answers

If you run IDLE, but you don't get a plot even with simple code in a Pyenv+VSCode environment, it's not a code problem, it's probably a problem with your environment.

Both Pyenv and VSCode are useful tools, but some parts are black boxed, so if they don't work the way you want, it takes time to find out.In this case, the following conditions are different from running on IDLE:

  • Impact of debugger ptvsd_launcher.py in between
  • VSCode Configuration Filelaunch.json, stings.json Impact
  • Python installed in Pyenv is not exactly the same effect as Python downloaded from the formula
  • The effect of matplotlib configuration files changing when the environment is different
  • Installing Pyenv adds $HOME/.pyenv/bin to the beginning of the PATH, which affects it

To resolve this issue, you must first change these conditions to find out where the problem lies.If you run with IDLE, it will be displayed, so you should try running with VSCode instead of IDLE and start with whether or not the plot will be printed.


2022-09-29 22:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.