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

Skip to content

Commit 3e80c3e

Browse files
committed
Added plot_trisurf to examples.
This produces an example plot of a 3D surface (in this case, the pringle function) on a triangular grid.
1 parent e80fc87 commit 3e80c3e

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

examples/mplot3d/trisurf3d_demo.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from mpl_toolkits.mplot3d import Axes3D
2+
from matplotlib import cm
3+
import matplotlib.pyplot as plt
4+
import numpy as np
5+
import math
6+
7+
n_angles = 36
8+
n_radii = 8
9+
min_radius = 0.25
10+
radii = np.linspace(min_radius, 0.95, n_radii)
11+
12+
angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False)
13+
angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1)
14+
angles[:,1::2] += math.pi/n_angles
15+
16+
x = np.append(0, (radii*np.cos(angles)).flatten())
17+
y = np.append(0, (radii*np.sin(angles)).flatten())
18+
z = np.sin(-x*y)
19+
20+
fig = plt.figure()
21+
ax = fig.gca(projection='3d')
22+
23+
ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.2)
24+
25+
plt.show()

0 commit comments

Comments
 (0)