Matplotlib, avoiding unwanted triangles in plot_trisurf()

前端 未结 1 1350
太阳男子
太阳男子 2021-01-05 02:04

I have the following code to create a cone for which a displacement field will be applied later on. In the figure shown below you can see that some big triangles are drawn a

相关标签:
1条回答
  • 2021-01-05 02:43

    You have probably moved on or solved this yourself by now, but I thought I'd throw an answer up for future vistors.

    The reason you are getting triangles in the smaller circle is not a max-distance thing, it is because those triangles are contained within the convex hull of your points projection on the x,y plane.

    If you look at the plot_trisurf source, (numpy.source(Axes3D.plot_trisurf)) you'll see that it performs delaunay triangulation every time and there is no opportunity to define your triangles or exclude unwanted triangles.

    Two options:

    the right way #1

    copy the source of plot_trisurf to your script and add the line tri.set_mask(...) (tri is a matplotlib.tri.triangulation.Triangulation instance) using the algo of your choice (some max edge length criteria or find triangles who centroids are within some radius.. whatever suits your actual data) to create the boolean mask after triangulation is done.

    the right way #2

    define the triangles without using delaunay triangluation using Triangulation(x,y,triangles=...)

    the quick way

    set plot_trisurf vmax to be slightly below the plane of the circle.

    *I didn't try either of these options

    0 讨论(0)
提交回复
热议问题