熊猫数据框的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轴值,并且 class 表示其属于哪一类(用于着色)

我该怎么做?

wu_qsh 回答:熊猫数据框的3D图

一种可能的解决方案是使用matplotlib的{​​{1}}(请参阅文档here),例如

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() 数据帧变量。

本文链接:https://www.f2er.com/3119885.html

大家都在问