2016-07-11 3 views
1

루프를 사용하여 플롯을 분산시키는 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]) 

답변

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() 
관련 문제