2015-11-14 45 views

回答

0

這是可能的着色使用facecolors關鍵字,它需要對每個小區中的RGB(A)值的特定區域(小區)。你可以手動創建它(一個shape(z) RGB(A)值的數組),但也可以使用顏色映射。例如,使用全球例如,從matplotlib

from mpl_toolkits.mplot3d import Axes3D 
import matplotlib.pyplot as plt 
import numpy as np 

plt.close('all') 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 

u = np.linspace(0, 2 * np.pi, 100) 
v = np.linspace(0, np.pi, 100) 

x = 10 * np.outer(np.cos(u), np.sin(v)) 
y = 10 * np.outer(np.sin(u), np.sin(v)) 
z = 10 * np.outer(np.ones(np.size(u)), np.cos(v)) 

# When creating `c` from data, `c` needs to be normalized to {0-1} 
c = np.zeros_like(z) 
c[30:40,30:40] = 1 

ax.plot_surface(x, y, z, rstride=2, cstride=2, facecolors=plt.cm.PuBu(c)) 

enter image description here

或者,如果想手動指定顏色:

c = np.ones((100,100,4))    # shape(z) x 4 array 
c[:,:,:] = [0.9, 0.5, 0.1, 1]   # R,G,B,A color globe 
c[30:40,30:40,:] = [0.4, 0.3, 0.2, 1] # R,G,B,A color patch 
ax.plot_surface(x, y, z, rstride=2, cstride=2, facecolors=c) 

enter image description here

相關問題