8

我有以下代码来创建一个圆锥体,稍后将为其应用位移场。在下图中,您可以看到顶部绘制了一些大三角形,但底部没有绘制。我相信有一些内部隐藏参数可以告诉plot_trisurf()应该创建三角形的距离,否则它们也应该在底部创建。

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from numpy import linspace, interp, meshgrid, sin, cos, pi
numel_circum = 120
L = 38.
rb, rt = (38., 16.)
t1, t2 = (0, 2*pi)
rav = ( rb - rt )*rt/rb + rt
perav = (t2-t1) * rav
elsize_L = perav / numel_circum
numel_L = int(round(L/elsize_L,0))
ts = linspace(t1, t2, numel_circum)
r = lambda z: interp( z, [0, L], [rb, rt] )
zs = linspace(0, L, numel_L)
ts, zs = meshgrid( ts, zs )
ys = r(zs)*sin(ts)
xs = r(zs)*cos(ts)
# plotting
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(xs.flatten(), ys.flatten(), zs.flatten(),
                cmap=cm.jet, linewidth=0.2)
plt.show()

在此处输入图像描述

4

1 回答 1

4

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

于 2013-05-14T03:44:10.010 回答