python数据可视化散点图案例_Python数据可视化—散点图_python 数据可视化
Python數(shù)據(jù)可視化—散點圖
PS: 翻了翻草稿箱, 發(fā)現(xiàn)居然存了一篇去年2月的文章。。。雖然naive,還是發(fā)出來吧。。。
本文記錄了Python中的數(shù)據(jù)可視化——散點圖scatter,
令x作為數(shù)據(jù)(50個點,每個30維),我們僅可視化前兩維。labels為其類別(假設有三類)。
這里的x就用random來了,具體數(shù)據(jù)具體分析。
label設定為[1:20]->1, [21:35]->2, [36:50]->3,(python中數(shù)組連接方法:先強制轉(zhuǎn)為list,用+,再轉(zhuǎn)回array)
用matplotlib的scatter繪制散點圖,legend和matlab中稍有不同,詳見代碼。
x = rand(50,30)
from numpy import *
import matplotlib
import matplotlib.pyplot as plt
#basic
f1 = plt.figure(1)
plt.subplot(211)
plt.scatter(x[:,1],x[:,0])
# with label
plt.subplot(212)
label = list(ones(20))+list(2*ones(15))+list(3*ones(15))
label = array(label)
plt.scatter(x[:,1],x[:,0],15.0*label,15.0*label)
# with legend
f2 = plt.figure(2)
idx_1 = find(label==1)
p1 = plt.scatter(x[idx_1,1], x[idx_1,0], marker = ‘x‘, color = ‘m‘, label=‘1‘, s = 30)
idx_2 = find(label==2)
p2 = plt.scatter(x[idx_2,1], x[idx_2,0], marker = ‘+‘, color = ‘c‘, label=‘2‘, s = 50)
idx_3 = find(label==3)
p3 = plt.scatter(x[idx_3,1], x[idx_3,0], marker = ‘o‘, color = ‘r‘, label=‘3‘, s = 15)
plt.legend(loc = ‘upper right‘)
result:
figure(1):
figure(2):
喜歡 (0)or分享 (0)
總結
以上是生活随笔為你收集整理的python数据可视化散点图案例_Python数据可视化—散点图_python 数据可视化的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ajax php 返回数组并父子给变量,
- 下一篇: xss跨站脚本攻击_常见攻击之xss跨站