Skip to content

Commit 51fff64

Browse files
Added clim support to tri/tripcolor
1 parent a2a1b0a commit 51fff64

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

lib/matplotlib/tests/test_triangulation.py

+9
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,15 @@ def test_tripcolor_color():
266266
ax.tripcolor(x, y, facecolors=[1, 2]) # faces
267267

268268

269+
def test_tripcolor_clim():
270+
(a, b, c) = np.random.rand(10), np.random.rand(10), np.random.rand(10)
271+
272+
ax = plt.figure().add_subplot()
273+
clim = (0.25, 0.75)
274+
norm = ax.tripcolor(a, b, c, clim=clim).norm
275+
assert((norm.vmin, norm.vmax) == clim)
276+
277+
269278
def test_tripcolor_warnings():
270279
x = [-1, 0, 1, 0]
271280
y = [0, -1, 0, 1]

lib/matplotlib/tri/tripcolor.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ def tripcolor(ax, *args, alpha=1.0, norm=None, cmap=None, vmin=None,
120120
raise ValueError(
121121
"shading='gouraud' can only be used when the colors "
122122
"are specified at the points, not at the faces.")
123-
collection = TriMesh(tri, **kwargs)
124-
colors = point_colors
123+
_api.check_isinstance((Normalize, None), norm=norm)
124+
collection = TriMesh(tri, alpha=alpha, array=point_colors,
125+
cmap=cmap, norm=norm, **kwargs)
125126
else:
126127
# Vertices of triangles.
127128
maskedTris = tri.get_masked_triangles()
@@ -137,13 +138,10 @@ def tripcolor(ax, *args, alpha=1.0, norm=None, cmap=None, vmin=None,
137138
else:
138139
colors = facecolors
139140

140-
collection = PolyCollection(verts, **kwargs)
141+
_api.check_isinstance((Normalize, None), norm=norm)
142+
collection = PolyCollection(verts, alpha=alpha, array=colors,
143+
cmap=cmap, norm=norm, **kwargs)
141144

142-
collection.set_alpha(alpha)
143-
collection.set_array(colors)
144-
_api.check_isinstance((Normalize, None), norm=norm)
145-
collection.set_cmap(cmap)
146-
collection.set_norm(norm)
147145
collection._scale_norm(norm, vmin, vmax)
148146
ax.grid(False)
149147

0 commit comments

Comments
 (0)