matplotlib散點(diǎn)圖這是最后一片萄凤,下次是誤差線,先來(lái)看幾個(gè)圖
接下來(lái)看代碼
import matplotlibas mat
import? numpyas np
import? matplotlib.pyplotas plt
x=np.linspace(-5,60,200)
y=np.sin(x)
fig =plt.figure()
plt.subplot(2,1,1)
plt.plot(x,y,'-or',label='sinx')
plt.legend()
plt.subplot(2,1,2)
plt.scatter(x,y,marker='o',label='sinxx')
plt.legend()
fig=plt.figure()
ran =np.random.RandomState(0)
x1=ran.randn(100)
y1=ran.randn(100)
color=ran.rand(100)
size=1000*ran.rand(100)
plt.scatter(x1,y1,c=color,s=size,alpha=0.3,cmap='viridis')
plt.colorbar()
plt.show()
我們將數(shù)據(jù)可視化秒拔,這幾行代碼生成三個(gè)圖像,分別為
首先生成模擬數(shù)據(jù)恶导,通過(guò)scatter函數(shù)怠硼,將數(shù)據(jù)可視化,但是啊因?yàn)槿鐖D形的渲染每個(gè)圖像都不同私沮,所以和函數(shù)plot相比始赎,速度要慢上不少,數(shù)據(jù)量越大仔燕,越要求使用plot函數(shù)造垛,c,s
晰搀,alpalt參數(shù)分別是顏色序列五辽,像素點(diǎn)大小,和透明度外恕,下面給出一個(gè)鳶尾花數(shù)據(jù)可視化的例子
????????from sklearn.datasetsimport load_iris
import? numpyas np
import matplotlib.pyplotas plt
iris =load_iris()
features =iris.data.T
plt.scatter(features[0],features[1],alpha=0.2,s=100*features[3],c=iris.target,cmap='viridis')
plt.xlabel(iris.feature_names[0])
plt.ylabel(iris.feature_names[1])
plt.show()
和效果圖
點(diǎn)大小表示花瓣寬度奔脐,
代碼有疑問(wèn)留言和我交流吧,喜歡就點(diǎn)贊吁讨,行賞的話就髓迎。。你懂的