繁体   English   中英

Pandas Dataframe 的 3D Plot

[英]3D Plot of a Pandas Dataframe

我有一个 Pandas Dataframe 有 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]

I want to create a 3D scatter plot with the first 3 columns as X,Y,Z axes values and class denoting which class it belongs to (use it for colouring)

我该怎么做?

一种可能的解决方案是使用matplotlibscatter3D() (请参阅此处的文档),例如

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数据框变量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM