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()
相关推荐
默_笙3 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
小羊没烦恼!3 天前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#
qq_426003963 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫3 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
长沙三为智能科技3 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
伞伞悦读3 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
只睡四小时3 天前
Canvas 弹道联机实战:700 行 + 固定时间步长
python·websocket·html5·游戏开发·canvas
C语言小火车3 天前
C/C++ 为什么需要编译器?
开发语言·c++
奇思妙想聪明勤奋的小羊3 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
lpfasd1233 天前
2026年第38周GitHub趋势周报
python·科技·github