我想在 3D 图中表示一个二进制 3D 矩阵(如果可能的话,不使用 mayavi.mlab)。应在矩阵具有 1 a 点的每个位置 (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?)
最佳答案
听起来您需要一个散点图。看看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()
关于python - 在 python 中绘制二元 3D 矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42829643/