3d图形绘制颜色的点

时间:2018-10-02 18:29:42

标签: python numpy matplotlib 3d

我的目标是绘制以下数据的3d尺寸图:

(array([[-0.45940028, -1.07401008, -0.60800963],
       [-0.34535859, -0.80739745,  0.48825026],
      ...
       [-0.39106198, -0.91424521, -0.7051101 ]]), array([0, 0, 1, 1, ...
       1, 0, 1, 1, 0, 1, 0, 0]))

最后一个数组代表两种不同的颜色(颜色无关紧要)

如何创建一个3d图形并将其与该数据集相关联的颜色关联起来?

2 个答案:

答案 0 :(得分:1)

这里是使用数组切片并将最后一个数组用作颜色的方法

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

data = (np.array([[-0.45940028, -1.07401008, -0.60800963],[-0.34535859,-0.80739745,  0.48825026],[-0.14535859, -0.60739745,  0.68825026], [-0.44535859, -0.10739745,  0.28825026], [-0.64535859, -0.20739745,  0.18825026],[-0.39106198, -0.91424521, -0.7051101 ]]), np.array([0, 0, 1, 1, 1, 0]))

ax.scatter(data[0][:,0], data[0][:,1], data[0][:,2], zdir='z', s=80, c=data[1])

enter image description here

答案 1 :(得分:0)

您可以使用mplot3d:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
xs = [1,2,3,4,5]
ys = [1,2,3,4,5]
zs = [1,2,3,4,5]
ax.scatter(xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True, *args, **kwargs)

plt.show()