删除matplotlib plot-trisu中没有间隙的线框

2024-06-09 00:37:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用matplotlib/pyplot创建一个平滑的圆柱体。我改编了一个在线教程,并给出了以下最小示例:

from numpy import meshgrid,linspace,pi,sin,cos,shape
from matplotlib import pyplot
import matplotlib.tri as mtri
from mpl_toolkits.mplot3d import Axes3D

u,v = meshgrid(linspace(0,10,10),linspace(0,2*pi,20))
u = u.flatten()
v = v.flatten()

x = u
z = sin(v)
y = cos(v)

tri = mtri.Triangulation(u, v)

fig = pyplot.figure()
ax = fig.add_axes([0,0,1,1],projection='3d')
ax.plot_trisurf(x,y,z,triangles=tri.triangles,linewidth=0)

pyplot.show()

产生一个cylinder。我设置linewidth=0来移除线框,但是,现在有线框的“重影”,因为假设线框是用来填充空白的,所以三角剖分(大概)已经间隔了。这看起来是特定于plot_trisurf的,因为还有其他3d绘图示例(例如using plot_surface)将linewidth=0设置为0,而不显示这些间隙。在

做一个mtri。三角测量?,似乎不可能“完美地”填补这些空白,因为它指出

^{pr2}$

一个部分解决方案是只给线框涂上相同的蓝色阴影,但是在我解决了这个问题之后,我还想在曲面上添加一个光源/阴影,这将使我回到原点。 有没有办法让它成功?或者有人能提出不同的方法吗?谢谢你的帮助。在


Tags: fromimport示例plotmatplotlibpisincos