【问题标题】:Removing wireframe without gaps in matplotlib plot_trisurf在 matplotlib plot_trisurf 中删除没有间隙的线框
【发布时间】:2016-07-01 13:31:02
【问题描述】:

我想使用 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 设置为没有显示这些间隙。

进行 mtri.Triangulation?,似乎不可能“完美”填补空白,因为它指出

>Notes
> -----
> For a Triangulation to be valid it must not have duplicate points,
> triangles formed from colinear points, or overlapping triangles.

一个部分解决方案是将线框着色为相同的蓝色阴影,但在我解决了这个问题之后,我还想在表面上添加一个光源/阴影,这会让我回到正方形。 有没有办法使这项工作?或者有人可以提出不同的方法吗?感谢您的帮助。

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:
    ax.plot_trisurf(x,y,z,triangles=tri.triangles,linewidth=0, antialiased=False)
    

    【讨论】:

    • 我可以发誓我试过了。显然不是。谢谢。