三角形三维填充等高线图

非结构化三角形网格的填充等高线图。

使用的数据与trisurf3d_demo2的第二个图中的数据相同。 tricontour3d_demo显示此示例的未填充版本。

三角形三维填充等高线图示例

  1. # This import registers the 3D projection, but is otherwise unused.
  2. from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
  3. import matplotlib.pyplot as plt
  4. import matplotlib.tri as tri
  5. import numpy as np
  6. # First create the x, y, z coordinates of the points.
  7. n_angles = 48
  8. n_radii = 8
  9. min_radius = 0.25
  10. # Create the mesh in polar coordinates and compute x, y, z.
  11. radii = np.linspace(min_radius, 0.95, n_radii)
  12. angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
  13. angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
  14. angles[:, 1::2] += np.pi/n_angles
  15. x = (radii*np.cos(angles)).flatten()
  16. y = (radii*np.sin(angles)).flatten()
  17. z = (np.cos(radii)*np.cos(3*angles)).flatten()
  18. # Create a custom triangulation.
  19. triang = tri.Triangulation(x, y)
  20. # Mask off unwanted triangles.
  21. triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1),
  22. y[triang.triangles].mean(axis=1))
  23. < min_radius)
  24. fig = plt.figure()
  25. ax = fig.gca(projection='3d')
  26. ax.tricontourf(triang, z, cmap=plt.cm.CMRmap)
  27. # Customize the view angle so it's easier to understand the plot.
  28. ax.view_init(elev=45.)
  29. plt.show()

下载这个示例