【发布时间】:2021-08-03 06:50:51
【问题描述】:
我有一张如下表。
根据上表,我想画出3维特征的分布。它包括三个类别,例如正常,超和低。我为此创建了以下代码。
%matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
labels = df.class_type
for l in labels:
attr1 = df.X1
attr2 = df.X2
attr3 = df.X3
ax.scatter(xs = attr1, ys = attr2, zs = attr3, label = "normal")
ax.scatter(xs = attr1, ys = attr2, zs = attr3, label = "hyper")
ax.scatter(xs = attr1, ys = attr2, zs = attr3, label = "hypo")
ax.set_title("1.Grup")
ax.set_xlabel("atr1")
ax.set_ylabel("atr2")
ax.set_zlabel("atr3")
plt.show()
但我想绘制如下图。我该怎么做?提前致谢
【问题讨论】:
-
您可以停止循环过程并修改以下内容以获得所需的输出。
ax.scatter(xs=attr1, ys=attr2, zs=attr3, c='b', label="normal");ax.scatter(xs=attr1, ys=attr3, zs=attr4, c='r', label="hyper");ax.scatter(xs=attr1, ys=attr4, zs=attr5, c='g', label="hypo")
标签: python dataframe matplotlib jupyter-notebook scatter3d