-
Notifications
You must be signed in to change notification settings - Fork 62
Closed
Description
I want to plot the Delaunay triangulation directly with plot_trisurf from mplot3d because the grid interpolation consumes too much memory, but the resulting surface is a jumble of triangles even though learner.npoints is 71016.
interp = learner.interpolator()
qhull = interp.tri
mptri = mpl.tri.Triangulation\
( x = qhull.points[:, 0]
, y = qhull.points[:, 1]
, triangles = qhull.vertices
)
fig = plt.figure()
ax = plt.axes(projection="3d")
ax.plot_trisurf\
(mptri, interp.values[:, 0], cmap="viridis")The issue appears related to the way adaptive triangulates the mesh, because I can create a triangulation from a regular grid without any issues:
x = np.linspace(-100, 100, 1000)
y = np.linspace(-100, 100, 1000)
X, Y = np.meshgrid(x, y)
Z = func(X, Y, ...)
xr = np.ravel(X)
yr = np.ravel(Y)
zr = np.ravel(Z)
interp = scipy.interpolate.LinearNDInterpolator\
(np.vstack([xr, yr]).T, zr)
qhull = interp.tri
mptri = mpl.tri.Triangulation\
( x = qhull.points[:, 0]
, y = qhull.points[:, 1]
, triangles = qhull.vertices
)
fig = plt.figure()
ax = plt.axes(projection="3d")
ax.plot_trisurf\
(mptri, interp.values[:, 0], cmap="viridis")It's interesting that the plot and interpolated_on_grid results return the expected surface, except that the output is transposed.
def func_wrapper(xy):
return func(xy[0], xy[1], ...)
learner = adaptive.Learner2D\
(test_func, bounds=[(-100,100), (-100, 100)])
runner = adaptive.BlockingRunner\
(learner, goal = lambda l: l.loss() < 0.00001)
x, y, Z = learner.interpolated_on_grid(4000)
# Un-transpose the output
Z = Z.T
X, Y = np.meshgrid(x, y)
fig = plt.figure()
ax = plt.axes(projection="3d")
ax.plot_surface(X, Y, Z, cmap="viridis")Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels