2016-07-11 18 views
1

ループを使用してプロットを散布する3Dデータキューブがあります。私は散布ポイントをキューブインデックスにし、散布ポイントの色をその値にします。以下は、すべての1つの色を生成するコードです。値に基づいて色をどうやって作るのですか?ループ生成散布図の色

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]) 

答えて

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()