matplotlib散點(diǎn)圖這是最后一片,下次是誤差線,先來看幾個圖


接下來看代碼
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ù)可視化,這幾行代碼生成三個圖像,分別為


首先生成模擬數(shù)據(jù),通過scatter函數(shù),將數(shù)據(jù)可視化,但是啊因?yàn)槿鐖D形的渲染每個圖像都不同,所以和函數(shù)plot相比,速度要慢上不少,數(shù)據(jù)量越大,越要求使用plot函數(shù),c,s
,alpalt參數(shù)分別是顏色序列,像素點(diǎn)大小,和透明度,下面給出一個鳶尾花數(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)大小表示花瓣寬度,
代碼有疑問留言和我交流吧,喜歡就點(diǎn)贊,行賞的話就。。你懂的