画图工具matplotlib简单实用--绘制散点图

python 中常用画图工具matplotlib.pyplot工具使用实验。

代码:

from sklearn.datasets.samples_generator import make_blobs
import matplotlib.pyplot as plt

X, y = make_blobs(n_samples=100, centers=3, n_features=2,random_state=0)
y=y+1;

# label
plt.figure(1)
ax=plt.subplot(121)
plt.scatter(X[:,0],X[:,1])
ax.set_title('No lable')
ax=plt.subplot(122)
plt.scatter(X[:,0],X[:,1],y*30,y*30)
ax.set_title('Have lable')

#
plt.figure(2)
ax=plt.subplot(111)
id=(y==1)
plt.scatter(X[id,0],X[id,1],s=20,color='b')
id=(y==2)
plt.scatter(X[id,0],X[id,1],s=50,color='r')
id=(y==3)
plt.scatter(X[id,0],X[id,1],s=70,color='g')
plt.show()

显示结果:

fiugre1


figure2







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值