2016-07-11 6 views
1

Ich habe einen 3D-Datenwürfel, den ich mit einer Schleife streuen. Ich möchte, dass die Streupunkte der Würfelindex und die Farbe der Streupunkte der Wert sind. Unten ist Code, der alle eine Farbe ergibt. Wie mache ich die Farben basierend auf dem Wert?Farben für Schleifen-Streudiagramm

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

Antwort

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