我正在使用带有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代码运行得很流畅,没有错误,但没有出现绘图。怎样才能让绘图显示出来?
发布于 2017-03-04 09:30:23
你最后错过了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")https://stackoverflow.com/questions/42591034
复制相似问题