Skip to content

Commit

Permalink
Merge pull request matplotlib#850 from ianthomas23/811_tripcolor_centred
Browse files Browse the repository at this point in the history
Added tripcolor triangle-centred colour values.
  • Loading branch information
efiring committed Aug 16, 2012
2 parents b68440f + 4f5d3ce commit 360887a
Show file tree
Hide file tree
Showing 7 changed files with 1,348 additions and 35 deletions.
20 changes: 12 additions & 8 deletions examples/pylab_examples/tripcolor_demo.py
Expand Up @@ -32,19 +32,19 @@
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
triang.set_mask(mask)

# pcolor plot.
# tripcolor plot.
plt.figure()
plt.gca().set_aspect('equal')
plt.tripcolor(triang, z, shading='flat', cmap=plt.cm.rainbow)
plt.colorbar()
plt.title('tripcolor of Delaunay triangulation: flat')
plt.title('tripcolor of Delaunay triangulation, flat shading')

# Illustrate Gouraud shading.
plt.figure()
plt.gca().set_aspect('equal')
plt.tripcolor(triang, z, shading='gouraud', cmap=plt.cm.rainbow)
plt.colorbar()
plt.title('tripcolor with Gouraud shading')
plt.title('tripcolor of Delaunay triangulation, gouraud shading')


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

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

xmid = x[triangles].mean(axis=1)
ymid = y[triangles].mean(axis=1)
x0 = -5
y0 = 52
zfaces = np.exp(-0.01*( (xmid-x0)*(xmid-x0) + (ymid-y0)*(ymid-y0) ))

# Rather than create a Triangulation object, can simply pass x, y and triangles
# arrays to tripcolor directly. It would be better to use a Triangulation object
# if the same triangulation was to be used more than once to save duplicated
# calculations.
# Can specify one color value per face rather than one per point by using the
# facecolors kwarg.
plt.figure()
plt.gca().set_aspect('equal')
plt.tripcolor(x, y, triangles, z, shading='flat', edgecolors='k',
cmap='summer')
plt.tripcolor(x, y, triangles, facecolors=zfaces, edgecolors='k')
plt.colorbar()
plt.title('tripcolor of user-specified triangulation')
plt.xlabel('Longitude (degrees)')
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/__init__.py
Expand Up @@ -1021,6 +1021,7 @@ def tk_window_focus():
'matplotlib.tests.test_legend',
'matplotlib.tests.test_colorbar',
'matplotlib.tests.test_patches',
'matplotlib.tests.test_triangulation'
]

def test(verbosity=1):
Expand Down
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 360887a

Please sign in to comment.