我想在3D绘图中表示一个二进制3D矩阵(如果可能,不要使用mayavi.mlab)。在矩阵为1的每个位置(x,y,z),应绘制一个点。我的矩阵是以如下方式构建的:
import numpy as np
size = 21
my_matrix = np.zeros(shape = (size, size, size))
random_location_1 = (1,1,2)
random_location_2 = (3,5,8)
my_matrix[random_location_1] = 1
my_matrix[random_location_2] = 1现在,在坐标(1,1,2)和(3,5,8)处,一个点应该是可见的,其他地方都是空的。有没有办法做到这一点(例如,使用matplotlib?)
发布于 2017-03-16 18:25:21
听起来你需要一个散点图。请看this mplot3d教程。对我来说,这是可行的:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
size = 21
m = np.zeros(shape = (size, size, size))
random_location_1 = (1,1,2)
random_location_2 = (3,5,8)
m[random_location_1] = 1
m[random_location_2] = 1
pos = np.where(m==1)
ax.scatter(pos[0], pos[1], pos[2], c='black')
plt.show()https://stackoverflow.com/questions/42829643
复制相似问题