我有一个3D数据立方体,我使用循环分散绘图。我希望散点图是立方体索引,散点的颜色是值。下面是产生所有一种颜色的代码。如何根据值制作颜色?
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
%matplotlib
# I have a 3D array of numbers of unknown shape containing unknown
# integer values within an unknown range.
# Here, I made this toy 3D array with shape 9,10,11 containing random
# integer values 0-10.
xyz = np.random.rand(9,10,111)*100//10
# Determine the shape of the the array
x_size = np.shape(xyz)[0]
y_size = np.shape(xyz)[1]
z_size = np.shape(xyz)[2]
# Scatter plot the array
fig = plt.figure()
ax = fig.add_subplot(111, projection = '3d')
for xi in range(x_size):
for yi in range(y_size):
for zi in range(z_size):
ax.scatter(xi, yi, zi, c=xyz[xi, yi, zi])
答案 0 :(得分:1)
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
# I have a 3D array of numbers of unknown shape containing unknown
# integer values within an unknown range.
# Here, I made this toy 3D array with shape 9,10,11 containing random
# integer values 0-10.
xyz = np.random.rand(9,10,111)*100//10
# Determine the shape of the the array
x_size = np.shape(xyz)[0]
y_size = np.shape(xyz)[1]
z_size = np.shape(xyz)[2]
# Scatter plot the array
fig = plt.figure()
ax = fig.add_subplot(111, projection = '3d')
xi, yi, zi = np.meshgrid(range(x_size), range(y_size), range(z_size))
ax.scatter(xi, yi, zi, c=xyz)
plt.show()