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

Skip to content

Commit f5f357e

Browse files
committed
Added tripcolor facecolors example.
1 parent 8a21c57 commit f5f357e

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

examples/pylab_examples/tripcolor_demo.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@
3232
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
3333
triang.set_mask(mask)
3434

35-
# pcolor plot.
35+
# tripcolor plot.
3636
plt.figure()
3737
plt.gca().set_aspect('equal')
3838
plt.tripcolor(triang, z, shading='flat', cmap=plt.cm.rainbow)
3939
plt.colorbar()
40-
plt.title('tripcolor of Delaunay triangulation: flat')
40+
plt.title('tripcolor of Delaunay triangulation, flat shading')
4141

4242
# Illustrate Gouraud shading.
4343
plt.figure()
4444
plt.gca().set_aspect('equal')
4545
plt.tripcolor(triang, z, shading='gouraud', cmap=plt.cm.rainbow)
4646
plt.colorbar()
47-
plt.title('tripcolor with Gouraud shading')
47+
plt.title('tripcolor of Delaunay triangulation, gouraud shading')
4848

4949

5050
# You can specify your own triangulation rather than perform a Delaunay
@@ -70,9 +70,6 @@
7070
[-0.057,0.916],[-0.025,0.933],[-0.077,0.990],[-0.059,0.993] ])
7171
x = xy[:,0]*180/3.14159
7272
y = xy[:,1]*180/3.14159
73-
x0 = -5
74-
y0 = 52
75-
z = np.exp(-0.01*( (x-x0)*(x-x0) + (y-y0)*(y-y0) ))
7673

7774
triangles = np.asarray([
7875
[67,66, 1],[65, 2,66],[ 1,66, 2],[64, 2,65],[63, 3,64],[60,59,57],
@@ -90,14 +87,21 @@
9087
[32,31,33],[39,38,72],[33,72,38],[33,38,34],[37,35,38],[34,38,35],
9188
[35,37,36] ])
9289

90+
xmid = x[triangles].mean(axis=1)
91+
ymid = y[triangles].mean(axis=1)
92+
x0 = -5
93+
y0 = 52
94+
zfaces = np.exp(-0.01*( (xmid-x0)*(xmid-x0) + (ymid-y0)*(ymid-y0) ))
95+
9396
# Rather than create a Triangulation object, can simply pass x, y and triangles
9497
# arrays to tripcolor directly. It would be better to use a Triangulation object
9598
# if the same triangulation was to be used more than once to save duplicated
9699
# calculations.
100+
# Can specify one color value per face rather than one per point by using the
101+
# facecolors kwarg.
97102
plt.figure()
98103
plt.gca().set_aspect('equal')
99-
plt.tripcolor(x, y, triangles, z, shading='flat', edgecolors='k',
100-
cmap='summer')
104+
plt.tripcolor(x, y, triangles, facecolors=zfaces, edgecolors='k')
101105
plt.colorbar()
102106
plt.title('tripcolor of user-specified triangulation')
103107
plt.xlabel('Longitude (degrees)')

0 commit comments

Comments
 (0)