30 lines
727 B
Python
30 lines
727 B
Python
|
|
import matplotlib.pyplot as plt
|
|
import random
|
|
|
|
|
|
# 创建一个 3D 图形
|
|
fig = plt.figure()
|
|
ax = fig.add_subplot(111, projection='3d')
|
|
|
|
# 为每个 key 分配一个随机颜色
|
|
colors = {"orange":(1,0,0),"yellow":(0,1,0)}
|
|
# for key in d.keys():
|
|
# colors[key] = (random.random(), random.random(), random.random()) # 随机 RGB 颜色
|
|
|
|
# 绘制每个 key 的点
|
|
for key, points in d.items():
|
|
x_vals = [point[0] for point in points]
|
|
y_vals = [point[1] for point in points]
|
|
z_vals = [point[2] for point in points]
|
|
ax.scatter(x_vals, y_vals, z_vals, label=key, color=colors[key])
|
|
|
|
# 添加图例和标签
|
|
ax.set_xlabel('X轴')
|
|
ax.set_ylabel('Y轴')
|
|
ax.set_zlabel('Z轴')
|
|
ax.legend()
|
|
|
|
# 显示图形
|
|
plt.show()
|