Matplotlib:使用TRISURF的GRID和COLORMAP

问题描述

我想在我的表面上放置一个网格,但是即使线宽不为零也不起作用,我还想绘制一个颜色图,该颜色图会随着Z轴的变化而改变颜色,因此墙壁应该以相同的颜色显示cos是Z的0.5点。希望有人能帮助我,谢谢。

这是我遇到问题的代码部分:

fig = plt.figure()
ax = Axes3D(fig)
surf = ax.plot_trisurf(x,y,z,cmap=plt.cm.get_cmap('jet',4),shade=False,linewidth=0.1,antialiased=False

This is my plot with a bad colormap and no grid

This is something similar to I want: with grid and a good colormap

解决方法

这是您想要的吗?

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

t = np.linspace(0,50)
X,Y = np.meshgrid(t,t)
Z = np.zeros_like(X)
Z[:,0] = 0.5
Z[:,-1] = 0.5


fig = plt.figure()
ax = fig.gca(projection='3d')

ax.plot_surface(X,Y,Z,cmap=plt.cm.get_cmap('jet',256),linewidth=0.2,antialiased=True)

enter image description here