plt绘制 2维、3维散点图
2024-08-27 23:31:22
# 3维
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets.samples_generator import make_classification
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = Axes3D(fig)
data,labels=make_classification(n_samples=1000,n_features=3,n_redundant=0,n_informative=2,
random_state=1,n_clusters_per_class=2) unique_lables=set(labels)
colors=plt.cm.Spectral(np.linspace(0,1,len(unique_lables)))
for k,col in zip(unique_lables,colors):
x_k=data[labels==k]
ax.scatter3D(x_k[:,0],x_k[:,1],x_k[:, 2], c=col) # 开始绘制,x_k[:,0] 表示取第一维 plt.title('data by make_classification()')
plt.show()
# 2维
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets.samples_generator import make_classification
data,labels=make_classification(n_samples=100,n_features=2,n_redundant=0,n_informative=2,
random_state=5,n_clusters_per_class=2)
unique_lables=set(labels)
colors=plt.cm.Spectral(np.linspace(0,1,len(unique_lables)))
for k,col in zip(unique_lables,colors):
x_k=data[labels==k]
plt.plot(x_k[:,0],x_k[:,1],'o',markerfacecolor=col,markeredgecolor="k",
markersize=10)
plt.title('data by make_classification()')
plt.show()
最新文章
- Javascript对象创建
- ASM:《X86汇编语言-从实模式到保护模式》第13章:保护模式下内核的加载,程序的动态加载和执行
- codeforces 336C Vasily the Bear and Sequence(贪心)
- python基础===使用switch方法,减少使用if语句
- [转]ORACLE SQL解析之硬解析和软解析
- R语言︱异常值检验、离群点分析、异常值处理
- Metaphor of quotient space
- .Net Excel 导出图表Demo(柱状图,多标签页)
- centos docker 安装
- 22 python 初学(类,面向对象)
- 倒水问题(Fill, UVa 10603)
- git使用——分支
- ssh 设置反向代理
- hadoop之计数器和管道的mrunit测试
- img图片自适应宽和高[转]
- 【leetcode】198.HouseRobber
- 42.Trapping Rain Water---dp,stack,两指针
- $FFT$(快速傅里叶变换)
- 资产证券化(ABS)+ 特殊目的信托(SPV)
- Mysql数据操作《二》单表查询
热门文章
- Hibernate中OpenSessionInViewFilter(通常配置在web.xml文件中)的作用
- Spring 配置 事务的几种方式
- Java代码优化(一)
- Failed to get D-Bus connection: Operation not permitted
- python 几种方法实现随机生成8位同时包含数字、大写字符、小写字符密码的小程序
- sql 中如何查询某一列的数据在另一个表中有没有?
- c#使用NPOI快速导出到Excel
- 浏览器对HTTP请求的编码行为
- 【cocos2d-x 手游研发----精灵的八面玲珑】
- android界面