[英]matplotlib Plot does not appear
I am using python v3.6 with pycharm and anaconda. 我正在将python v3.6与pycharm和anaconda一起使用。 I tried to run the code below to plot a simple sine wave; 我试图运行下面的代码来绘制一个简单的正弦波。
import numpy as np
import matplotlib.pyplot as plt
# Generate a sequence of numbers from -10 to 10 with 100 steps in between
x = np.linspace(-10, 10, 100)
# Create a second array using sine
y = np.sin(x)
# The plot function makes a line chart of one array against another
plt.plot(x, y, marker="x")
pass
The code runs smoothly without error but no plot appears. 代码运行平稳,没有错误,但是没有显示任何图。 How do I get the plot to appear? 如何显示情节?
You're missing plt.show()
at the end. 您最后缺少plt.show()
。
import numpy as np
import matplotlib.pyplot as plt
# Generate a sequence of numbers from -10 to 10 with 100 steps in between
x = np.linspace(-10, 10, 100)
# Create a second array using sine
y = np.sin(x)
# The plot function makes a line chart of one array against another
plt.plot(x, y, marker="x")
plt.show()
pass
or, if you want to save it into a file 或者,如果您要将其保存到文件中
plt.savefig("my_file.png")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.