python - Pandas 数据框的 3D 图
问题描述
我有一个 Pandas 数据框,它有 4 列 - 3 列数据,第 4 列表示簇号
Col1 Col2 Col3 class
0 41.780730 -1.306569 -28.856727 0
1 36.421576 -7.654914 -32.675033 0
2 32.721677 -13.621913 -35.019806 0
3 42.028039 -12.280224 -39.521991 0
4 40.498716 -9.311412 -33.008553 0
... ... ... ... ...
14975 -54.303420 -5.444276 31.720262 1
14976 -63.230109 -12.673256 49.581873 1
14977 -63.609974 -11.004379 49.994068 1
14978 -52.682472 -10.969886 32.483284 1
14979 -37.329985 -19.290387 11.959876 1
[14980 rows x 4 columns]
我想创建一个 3D 散点图,前 3 列作为 X、Y、Z 轴值和表示它属于哪个类的类(用它来着色)
我该怎么做?
解决方案
一个可能的解决方案是使用matplotlib
's scatter3D()
(请参阅此处的文档),例如
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(10, 10))
ax = plt.axes(projection='3d')
ax.scatter3D(df['Col1'], df['Col2'], df['Col3'], c=df['class'])
plt.show()
数据框变量df
在哪里。
推荐阅读
- kotlin-coroutines - Kotlin:杀死一个不合作的协程
- websphere - IBM Watson Discovery 新闻 curl 禁止错误
- javascript - 如何使用输入滑块滚动 html 滚动部分,反之亦然
- code-coverage - DotCover Cobertura 或 OpenClover XML
- php - Symfony 在 EntityType 中使用了错误的实体类
- linux - 找不到 android sdkmanager 工具(颤振)
- mongodb - 如何对 MongoDB 中的嵌套字段进行全文搜索?
- python - 如何使用稀疏张量将 REST API 请求发送到 Tensorflow Serving 模型?
- c - 从格式字符串函数中查找字符
- python - Python使用线程事件作为对象成员