2016-03-01 33 views
14

我正在嘗試創建一個散點圖。我有一個從0到17的數字列表以及一個有18個值的數組。我可以將數據繪製爲線圖,但是當我嘗試繪製散點圖時,我收到一條錯誤消息,我不明白:TypeError: ufunc 'sqrt' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''Matplotlib散佈圖與未知錯誤

這條錯誤消息的含義是什麼,如何獲取要繪製的數據作爲分散?

import numpy as np 
import matplotlib.pyplot as plt 

y = [7316.0, 7453.25, 7518.25, 7711.5, 7448.0, 7210.25, 7416.75, 6960.75, 
    7397.75, 6397.5, 5522.75, 5139.0, 5034.75, 4264.75, 5106.0, 3489.5, 
    4712.0, 4770.0] 
x = np.arange(0,18,1) 

plt.rcParams['legend.loc'] = 'best' 
plt.figure(1) 
plt.xlim(0, 20) 
plt.ylim(0, 10000) 
plt.scatter(x, y, 'r') 
plt.show() 

回答

31

檢查scatter documentation。第三個參數是點的大小,應該是標量或類似的。我認爲'r'是顏色,所以做以下幾點:

plt.scatter(x, y, c='r') 
+1

謝謝你現在有道理。我正在閱讀它,但省略了c =部分,因爲它在正常情節中是不必要的。在兩種風格之間有不同的語法似乎很愚蠢。 –