python 3D散点图

python 复制代码
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt

#解决中文乱码和负号不显示问题
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] =False
fig = plt.figure()
ax = plt.axes(projection='3d')

#构造3个散点向量

x1=[[-0.0221,-0.0543,-0.0525],
 [0.0268,-0.0475,-0.04],
 [0.0733,-0.0537,-0.0142],
 [0.0645,0.0333,0.0796],
 [0.0063,0.0067,0.0573],
 [0.049,-0.055,0.0439],
 [-0.0443,-0.0177,0.0707]]
x2=[[-9.95538197e-03 ,-6.80566940e-04 ,-3.88511945e-03],
 [-3.16788722e-03 ,-2.95998948e-03 , 2.08909181e-03],
 [ 6.32466376e-02 ,-1.31060611e-02 , 3.58115090e-03],
 [-1.45574491e-02, -5.22264512e-03 ,-4.00055340e-03],
 [-1.05448766e-02 , 3.62097926e-05, -1.25675567e-03],
 [ 4.52933321e-03 ,-3.12502217e-03 , 4.04007733e-03],
 [-1.10306684e-02,  3.10038822e-03 , 1.03393774e-02],
 [-8.50945991e-03 , 1.84351373e-02  ,2.85878927e-02]]
x3=[[ 0.00024847,  0.00895313 , 0.00876404],
 [-0.02710083 , 0.03087348 ,-0.02424021],
 [-0.01565485 , 0.0263345 , -0.02861422],
 [ 0.02012201 ,-0.00851349 ,-0.01320678],
 [-0.0131679 ,  0.0031796 , -0.00676345],
 [ 0.01457987 , 0.02919558 , 0.01558889],
 [ 0.01512623 ,-0.00254833 , 0.00778025],
 [ 0.04662133 , 0.01249118 , 0.0103233 ]]

for i in x1:
    ax.scatter(i[0],i[1], i[2],c='black')
for i in x2:
    ax.scatter(i[0],i[1], i[2],c='blue')
for i in x3:
    ax.scatter(i[0],i[1], i[2],c='red')
#添加标题
ax.set_title(' this is a title')

#增加图例

ax.text(0.08,0.10,0.13, '蓝色:label2', fontsize = 8,color='blue')
ax.text(0.08,0.10,0.12, '黑色:label1', fontsize = 8,color='black')
ax.text(0.08,0.10,0.11, '红色:label3', fontsize = 8,color='red')

plt.show()
相关推荐
谢道韫6662 分钟前
今日总结 2024-12-27
开发语言·前端·javascript
夏娃同学4 分钟前
基于Flask后端框架的均值填充
python·flask
lili-felicity4 分钟前
指针与数组:深入C语言的内存操作艺术
c语言·开发语言·数据结构·算法·青少年编程·c#
HackKong10 分钟前
Python与黑客技术
网络·python·web安全·网络安全·php
四口鲸鱼爱吃盐14 分钟前
Pytorch | 利用GNP针对CIFAR10上的ResNet分类器进行对抗攻击
人工智能·pytorch·python·深度学习·神经网络·计算机视觉
进击的小小学生15 分钟前
多因子模型连载
大数据·python·数据分析·区块链
小码贾16 分钟前
OpenCV-Python实战(6)——图相运算
人工智能·python·opencv
大今野18 分钟前
node.js和js
开发语言·javascript·node.js
Just_Paranoid21 分钟前
使用 IDE生成 Java Doc
java·开发语言·ide
yma1624 分钟前
windows10下使用沙盒多开uiautoanimation可行性验证
python·uiautoanimation