Matplotlib:使用TRISURF的GRID和COLORMAP [英] Matplotlib: GRID and COLORMAP with TRISURF

查看:78
本文介绍了Matplotlib:使用TRISURF的GRID和COLORMAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是我遇到的代码问题:

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

)

I want to put a grid on my surface but it doesn't work even with linewidth different from zero, also I would like to plot a colormap that changes the color with Z axis, so the walls should appear with the same color cos they are points at 0.5 in Z. Hope somebody can help me, thanks.

This is the part of my code I'm having problem with:

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

解决方案

Is this you want?

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)

这篇关于Matplotlib:使用TRISURF的GRID和COLORMAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆