2016-06-13 9 views
0

ich habe 2 Arrays wie diesematplotlib scatter Array Längen nicht selber

x_test = [[ 14. 1.] [ 14. 2.] [ 14. 3.] [ 14. 4.] [ 14. 5.] [ 14. 6.] [ 14. 7.] [ 14. 8.] [ 14. 9.] [ 14. 10.] [ 14. 11.] [ 14. 12.]] 

y_test = [ 254.7 255.4 476.5 19.5 85.6 352. 238.7 144.8 83.5 278.8 449.6 312.7] 

i diese Anordnung soll scatter zeigen matplotlib verwenden.

dies ist mein Code

plt.scatter(x_test, y_test, color='black') 
plt.plot(x_test, y_predict, color='blue', linewidth=3) 

plt.xticks(()) 
plt.yticks(()) 

plt.show() 

und es gibt mir diesen Fehler

Traceback (most recent call last): 
    File "C:\wamp\www\python\test1.py", line 84, in <module> 
    plt.scatter(x_test, y_test, color='black') 
    File "C:\Python34\lib\site-packages\matplotlib\pyplot.py", line 3251, in scatter 
    edgecolors=edgecolors, data=data, **kwargs) 
    File "C:\Python34\lib\site-packages\matplotlib\__init__.py", line 1812, in inner 
    return func(ax, *args, **kwargs) 
    File "C:\Python34\lib\site-packages\matplotlib\axes\_axes.py", line 3840, in scatter 
    raise ValueError("x and y must be the same size") 
ValueError: x and y must be the same size 

beide Feldlänge sind die gleichen, und ich verstehe nicht, was das Problem hier ist. Bitte helfen Sie mir dank

dies ist mein y_predict Array

y_predict = [ 91.76428571 103.1   86.85714286 401.44642857 339.69642857 
    196.83571429 126.38928571 31.41071429 211.67857143 167.35357143 
    288.53214286 107.36785714] 

Antwort

1

Die x_test, wie Sie es vorgesehen ist, macht keinen Sinn für ein Streudiagramm. Und die Arrays sind eigentlich nicht die gleiche Größe:

print(x_test.shape) 
print(y_test.shape) 

(12, 2)

(12,)

Was Sie vielleicht stattdessen etwas haben wollen wie folgt aus (mit nur der zweiten Spalte von x_test):

plt.scatter(x_test[:,1], y_test, color='black') 
plt.plot(x_test[:,1], y_predict, color='blue', linewidth=3) 
+0

danke bro es funktioniert gut. –

Verwandte Themen