From 18ad35079c83fa4e40e5b47394456068cdea5e8f Mon Sep 17 00:00:00 2001 From: Andrew Fennell Date: Wed, 30 Mar 2022 11:37:30 -0500 Subject: [PATCH] Added clim support to tri/tripcolor --- lib/matplotlib/tests/test_triangulation.py | 10 ++++++++++ lib/matplotlib/tri/tripcolor.py | 14 +++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/tests/test_triangulation.py b/lib/matplotlib/tests/test_triangulation.py index 5243b25964da..ee2b28c47473 100644 --- a/lib/matplotlib/tests/test_triangulation.py +++ b/lib/matplotlib/tests/test_triangulation.py @@ -266,6 +266,16 @@ def test_tripcolor_color(): ax.tripcolor(x, y, facecolors=[1, 2]) # faces +def test_tripcolor_clim(): + np.random.seed(19680801) + a, b, c = np.random.rand(10), np.random.rand(10), np.random.rand(10) + + ax = plt.figure().add_subplot() + clim = (0.25, 0.75) + norm = ax.tripcolor(a, b, c, clim=clim).norm + assert((norm.vmin, norm.vmax) == clim) + + def test_tripcolor_warnings(): x = [-1, 0, 1, 0] y = [0, -1, 0, 1] diff --git a/lib/matplotlib/tri/tripcolor.py b/lib/matplotlib/tri/tripcolor.py index b4bd2fc4a761..6c3edc77600a 100644 --- a/lib/matplotlib/tri/tripcolor.py +++ b/lib/matplotlib/tri/tripcolor.py @@ -115,13 +115,14 @@ def tripcolor(ax, *args, alpha=1.0, norm=None, cmap=None, vmin=None, if 'antialiaseds' not in kwargs and ec.lower() == "none": kwargs['antialiaseds'] = False + _api.check_isinstance((Normalize, None), norm=norm) if shading == 'gouraud': if facecolors is not None: raise ValueError( "shading='gouraud' can only be used when the colors " "are specified at the points, not at the faces.") - collection = TriMesh(tri, **kwargs) - colors = point_colors + collection = TriMesh(tri, alpha=alpha, array=point_colors, + cmap=cmap, norm=norm, **kwargs) else: # Vertices of triangles. maskedTris = tri.get_masked_triangles() @@ -136,14 +137,9 @@ def tripcolor(ax, *args, alpha=1.0, norm=None, cmap=None, vmin=None, colors = facecolors[~tri.mask] else: colors = facecolors + collection = PolyCollection(verts, alpha=alpha, array=colors, + cmap=cmap, norm=norm, **kwargs) - collection = PolyCollection(verts, **kwargs) - - collection.set_alpha(alpha) - collection.set_array(colors) - _api.check_isinstance((Normalize, None), norm=norm) - collection.set_cmap(cmap) - collection.set_norm(norm) collection._scale_norm(norm, vmin, vmax) ax.grid(False)