|
21 | 21 |
|
22 | 22 | # The triangles in parameter space determnine which x, y, z points are |
23 | 23 | # connected by an edge |
24 | | -ax.plot_trisurf(x, y, z, triangles=tri.triangles) |
| 24 | +ax.plot_trisurf(x, y, z, triangles=tri.triangles, cmap=plt.cm.Spectral) |
25 | 25 |
|
26 | 26 | ax.set_zlim(-1, 1) |
27 | 27 | plt.show() |
| 28 | + |
| 29 | +# First create the x and y coordinates of the points. |
| 30 | +n_angles = 36 |
| 31 | +n_radii = 8 |
| 32 | +min_radius = 0.25 |
| 33 | +radii = np.linspace(min_radius, 0.95, n_radii) |
| 34 | + |
| 35 | +angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False) |
| 36 | +angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1) |
| 37 | +angles[:,1::2] += np.pi/n_angles |
| 38 | + |
| 39 | +x = (radii*np.cos(angles)).flatten() |
| 40 | +y = (radii*np.sin(angles)).flatten() |
| 41 | +z = (np.cos(radii)*np.cos(angles*3.0)).flatten() |
| 42 | + |
| 43 | +# Create the Triangulation; no triangles so Delaunay triangulation created. |
| 44 | +triang = mtri.Triangulation(x, y) |
| 45 | + |
| 46 | +# Mask off unwanted triangles. |
| 47 | +xmid = x[triang.triangles].mean(axis=1) |
| 48 | +ymid = y[triang.triangles].mean(axis=1) |
| 49 | +mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0) |
| 50 | +triang.set_mask(mask) |
| 51 | + |
| 52 | +# tripcolor plot. |
| 53 | +fig = plt.figure() |
| 54 | +ax = fig.add_subplot(1, 1, 1, projection='3d') |
| 55 | +ax.plot_trisurf(triang, z, cmap=plt.cm.CMRmap) |
| 56 | +plt.show() |
0 commit comments