matplotlib教程

散点图

我有两组数据,需要不同颜色的点将他们表示在一个二维空间中。

1
2
3
4
5
6
7
8
9
10
11
12
13
#plot trainning curve
f1=plt.figure(1)
#plot real training data
p1=plt.scatter(x_train[:,0]*x_max,y_train*y_max,marker='.',color='b',label='real price')
#plot gradient decent training curve
y_pre=np.dot(x_train,w_gd)*y_max
p2=plt.scatter(x_train[:,0]*x_max,y_pre,marker='x',color='r',label='gradient method predict price')
#plot normal equation training curve
y_pre=np.dot(x_train,w_eq)*y_max
p3=plt.scatter(x_train[:,0]*x_max,y_pre,marker='x',color='g',label='normal equation predict price')

plt.legend()
plt.show()

分享到