我正在使用带有 pycharm 和 anaconda 的 python v3.6。我试图运行下面的代码来绘制一个简单的正弦波;
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
代码运行顺利,没有错误,但没有出现任何情节。如何显示情节?
你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
或者,如果您要将其保存到文件中
plt.savefig("my_file.png")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句