2017-03-04 126 views
0

我使用python v3.6與pycharm和anaconda。我試圖運行下面的代碼來繪製一個簡單的正弦波;matplotlib不會出現劇情

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 

該代碼運行平穩無錯,但不出現任何情節。我如何讓情節出現?

回答

1

最後缺少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") 
+0

謝謝。我會將其標記爲答案。由於缺乏積分而無法得到滿意的結果。 – user3848207

+0

不是問題;) – ODiogoSilva