Matplotlib 曲面图显示不同值的相同颜色
Matplotlib surface plot showing same color for different values
为什么所有的点都得到相同的值?我希望颜色随能量变化。
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
ax.plot_surface(alpha, beta, energy, cstride=1, rstride=1, cmap='summer', vmin=energy.min(), vmax=energy.max())
注意 cstride
和 rstride
参数。
使用上面的答案(添加 cstride
和 rstride
参数),但想添加差异的可视化...
在我的例子中,我正在绘制地形...
没有步伐:
surf = ax.plot_surface(topo['lon'], topo['lat'], topo['value'],
cmap='terrain', vmax=2800, vmin=1300,
linewidth=.1, antialiased=False)
大步走:
surf = ax.plot_surface(topo['lon'], topo['lat'], topo['value'],
cmap='terrain', vmax=2800, vmin=1300,
linewidth=.1, antialiased=False,
rstride=1, cstride=1)
为什么所有的点都得到相同的值?我希望颜色随能量变化。
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
ax.plot_surface(alpha, beta, energy, cstride=1, rstride=1, cmap='summer', vmin=energy.min(), vmax=energy.max())
注意 cstride
和 rstride
参数。
使用上面的答案(添加 cstride
和 rstride
参数),但想添加差异的可视化...
在我的例子中,我正在绘制地形...
没有步伐:
surf = ax.plot_surface(topo['lon'], topo['lat'], topo['value'],
cmap='terrain', vmax=2800, vmin=1300,
linewidth=.1, antialiased=False)
大步走:
surf = ax.plot_surface(topo['lon'], topo['lat'], topo['value'],
cmap='terrain', vmax=2800, vmin=1300,
linewidth=.1, antialiased=False,
rstride=1, cstride=1)