Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3832496

Browse files
committed
Add Axes3D.contourf example
1 parent 528d10c commit 3832496

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
Contour plots of unstructured triangular grids.
3+
"""
4+
import matplotlib.pyplot as plt
5+
from mpl_toolkits.mplot3d import Axes3D
6+
import matplotlib.tri as tri
7+
import numpy as np
8+
import math
9+
10+
# First create the x and y coordinates of the points.
11+
n_angles = 48
12+
n_radii = 8
13+
min_radius = 0.25
14+
radii = np.linspace(min_radius, 0.95, n_radii)
15+
16+
angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False)
17+
angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1)
18+
angles[:,1::2] += math.pi/n_angles
19+
20+
x = (radii*np.cos(angles)).flatten()
21+
y = (radii*np.sin(angles)).flatten()
22+
z = (np.cos(radii)*np.cos(angles*3.0)).flatten()
23+
24+
# Create a custom triangulation
25+
triang = tri.Triangulation(x, y)
26+
27+
# Mask off unwanted triangles.
28+
xmid = x[triang.triangles].mean(axis=1)
29+
ymid = y[triang.triangles].mean(axis=1)
30+
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
31+
triang.set_mask(mask)
32+
33+
plt.figure()
34+
plt.gca(projection='3d')
35+
plt.tricontourf(triang, z)
36+
plt.show()

0 commit comments

Comments
 (0)