首页 > 解决方案 > 曲面图上的连续颜色图

问题描述

我想在 3D Surface Plot 上使用 matplotlib 创建一个连续的颜色图,其中颜色取决于表面的 z 值。但是使用“正常” plt 函数,颜色图会用相同的颜色填充网格点之间的空间,如图所示。所以颜色没有连续变化,而只是一些彩色表面缝合在一起:

x = range(0,126)
y = range(0,3)
#z is my data from the experiment

# make a grid of the x/y plane
X,Y= np.meshgrid(x,y)

# get the colormap for the graph
cmap=plt.get_cmap("RdBu")

# cmap = clr.LinearColormap.from_list('custom blue', ['#244162','#DCE6F1'], N=256)

#plot the corresponding z-value at every knot of the grid 
surface = ax.plot_surface(X,Y,z, cmap = cmap, antialiased=True, edgecolor='gray' , linewidth=0.2)

m = cm.ScalarMappable(cmap=surface.cmap,norm=surface.norm)
m.set_array(z)
plt.colorbar(m)

ax.set_yticks(y)
ax.set_xticks(x[::25])

plt.show()

看起来像这样: 3D-surface Plot

我是否需要在其间插入更多网格点的表面,还是有更优雅的方法?我对文档和语法有点迷茫

在此先感谢,masterblibla

标签: pythonmatplotlibcolormapcontinuous

解决方案


推荐阅读