2016-05-23 28 views
1

爲什麼所有的點都得到相同的值?我希望顏色隨能量而變化。表面圖colormap python

from mpl_toolkits.mplot3d import axes3d 
import matplotlib.pyplot as plt 
from matplotlib import cm 
from numpy import * 

x = linspace(0.2, 2, 11) 
y = linspace(0.1, 1, 11) 
alpha, beta = meshgrid(x,y) 
energy = matrix(loadtxt('energyPlotfileN6.txt')) 

fig = plt.figure() 
ax = fig.gca(projection='3d') 
ax.plot_surface(alpha, beta, energy, cmap='summer', vmin=energy.min(), vmax=energy.max()) 
plt.xlabel("alpha") 
plt.ylabel("beta") 
ax.set_zlabel("energy") 
plt.show() 

結果示下面

Surface plot without desired colour mapping

+1

你得到,如果你更換'CMAP ='與'CMAP = cm.summer' summer''相同的輸出? – jonchar

+0

是的,我喜歡。 @jonchar – filiphl

回答

1
ax.plot_surface(alpha, beta, energy, cstride=1, rstride=1, cmap='summer', vmin=energy.min(), vmax=energy.max()) 

注意cstriderstride參數。

Axes3D.plot_surface documentation

+0

阿門使用cstride和rstride參數! – blaylockbk

0

從上面使用的答案(添加cstriderstride參數),但想補充的差異的可視化...

在我的情況,我繪製地形...

無步幅:

surf = ax.plot_surface(topo['lon'], topo['lat'], topo['value'], 
         cmap='terrain', vmax=2800, vmin=1300, 
         linewidth=.1, antialiased=False) 

enter image description here

步幅:

surf = ax.plot_surface(topo['lon'], topo['lat'], topo['value'], 
          cmap='terrain', vmax=2800, vmin=1300, 
          linewidth=.1, antialiased=False, 
          rstride=1, cstride=1) 

enter image description here