matplotlib图不出现 [英] matplotlib Plot does not appear
本文介绍了matplotlib图不出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将python v3.6与pycharm和anaconda一起使用.我试图运行下面的代码来绘制一个简单的正弦波.
I am using python v3.6 with pycharm and 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?
推荐答案
您最后缺少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")
这篇关于matplotlib图不出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文