| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8a21c57 commit f5f357e
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,19 +32,19 @@ | |||
| 32 | 32 | mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0) | |
| 33 | 33 | triang.set_mask(mask) | |
| 34 | 34 | ||
| 35 | - # pcolor plot. | ||
| 35 | + # tripcolor plot. | ||
| 36 | 36 | plt.figure() | |
| 37 | 37 | plt.gca().set_aspect('equal') | |
| 38 | 38 | plt.tripcolor(triang, z, shading='flat', cmap=plt.cm.rainbow) | |
| 39 | 39 | plt.colorbar() | |
| 40 | - plt.title('tripcolor of Delaunay triangulation: flat') | ||
| 40 | + plt.title('tripcolor of Delaunay triangulation, flat shading') | ||
| 41 | 41 | ||
| 42 | 42 | # Illustrate Gouraud shading. | |
| 43 | 43 | plt.figure() | |
| 44 | 44 | plt.gca().set_aspect('equal') | |
| 45 | 45 | plt.tripcolor(triang, z, shading='gouraud', cmap=plt.cm.rainbow) | |
| 46 | 46 | plt.colorbar() | |
| 47 | - plt.title('tripcolor with Gouraud shading') | ||
| 47 | + plt.title('tripcolor of Delaunay triangulation, gouraud shading') | ||
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | 50 | # You can specify your own triangulation rather than perform a Delaunay | |
@@ -70,9 +70,6 @@ | |||
| 70 | 70 | [-0.057,0.916],[-0.025,0.933],[-0.077,0.990],[-0.059,0.993] ]) | |
| 71 | 71 | x = xy[:,0]*180/3.14159 | |
| 72 | 72 | 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) )) | ||
| 76 | 73 | ||
| 77 | 74 | triangles = np.asarray([ | |
| 78 | 75 | [67,66, 1],[65, 2,66],[ 1,66, 2],[64, 2,65],[63, 3,64],[60,59,57], | |
@@ -90,14 +87,21 @@ | |||
| 90 | 87 | [32,31,33],[39,38,72],[33,72,38],[33,38,34],[37,35,38],[34,38,35], | |
| 91 | 88 | [35,37,36] ]) | |
| 92 | 89 | ||
| 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 | + | ||
| 93 | 96 | # Rather than create a Triangulation object, can simply pass x, y and triangles | |
| 94 | 97 | # arrays to tripcolor directly. It would be better to use a Triangulation object | |
| 95 | 98 | # if the same triangulation was to be used more than once to save duplicated | |
| 96 | 99 | # calculations. | |
| 100 | + # Can specify one color value per face rather than one per point by using the | ||
| 101 | + # facecolors kwarg. | ||
| 97 | 102 | plt.figure() | |
| 98 | 103 | 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') | ||
| 101 | 105 | plt.colorbar() | |
| 102 | 106 | plt.title('tripcolor of user-specified triangulation') | |
| 103 | 107 | plt.xlabel('Longitude (degrees)') | |
| Back | FazBrowse Home | New Git URL |
0 commit comments