python散點圖屬性&用不同顏色展示不同的分類結果(分類著色)
阿新 • • 發佈:2019-01-09
x:指定散點圖的x軸資料;
y:指定散點圖的y軸資料;
s:指定散點圖點的大小,預設為20,通過傳入新的變數,實現氣泡圖的繪製;
c:可用於不同類別的顏色,指定散點圖點的顏色,預設為藍色;
marker:指定散點圖點的形狀,預設為圓形;
cmap:指定色圖,只有當c引數是一個浮點型的陣列的時候才起作用;
alpha:設定散點的透明度;
linewidths:設定散點邊界線的寬度;
edgecolors:設定散點邊界線的顏色;
對於畫多重顏色的散點圖,將不同顏色的資料用labels分開就好。在這裡舉一個混合高斯分佈的例子:
# labels = gmm.predict(Dist)
#plot and save figure
fig1 = plt.figure(1,figsize=(6,4))
colors = ['b','g','r','orange']
Label_Com = ['Component 1','Component 2','Component 3','Component 4']
for index in range(4):
Price = data.loc[data['Label'] == index]['Price']
# Price = Dist[Labels[i] == index]
Index = data.loc[data['Label' ] == index]['Number']
print("Done")
plt.scatter(Index, Price, c=colors[index], cmap='brg', s=40, alpha=0.2, marker='8', linewidth=0) # ,cMAP
plt.ylim(0.01,0.09)
ax = fig1.gca()
for label in ax.xaxis.get_ticklabels():
label.set_rotation(30)
plt.xlabel('Time')
plt.ylabel('Price')
#added this to get the legend to work
handles,labels = ax.get_legend_handles_labels()
ax.legend(handles, labels = Label_Com, loc='upper right')
plt.show()