1""" 2================================= 3Triangular 3D filled contour plot 4================================= 5 6Filled contour plots of unstructured triangular grids. 7 8The data used is the same as in the second plot of trisurf3d_demo2. 9tricontour3d_demo shows the unfilled version of this example. 10""" 11 12import matplotlib.pyplot as plt 13import matplotlib.tri as tri 14import numpy as np 15 16# First create the x, y, z coordinates of the points. 17n_angles = 48 18n_radii = 8 19min_radius = 0.25 20 21# Create the mesh in polar coordinates and compute x, y, z. 22radii = np.linspace(min_radius, 0.95, n_radii) 23angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False) 24angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1) 25angles[:, 1::2] += np.pi/n_angles 26 27x = (radii*np.cos(angles)).flatten() 28y = (radii*np.sin(angles)).flatten() 29z = (np.cos(radii)*np.cos(3*angles)).flatten() 30 31# Create a custom triangulation. 32triang = tri.Triangulation(x, y) 33 34# Mask off unwanted triangles. 35triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1), 36 y[triang.triangles].mean(axis=1)) 37 < min_radius) 38 39ax = plt.figure().add_subplot(projection='3d') 40ax.tricontourf(triang, z, cmap=plt.cm.CMRmap) 41 42# Customize the view angle so it's easier to understand the plot. 43ax.view_init(elev=45.) 44 45plt.show() 46