Skip to content

Added clim support to tripcolor #22734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/test_triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 5 additions & 9 deletions lib/matplotlib/tri/tripcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand Down