diff --git a/lib/matplotlib/cm.py b/lib/matplotlib/cm.py index 6ed13cd2f41d..081f5415ab8d 100644 --- a/lib/matplotlib/cm.py +++ b/lib/matplotlib/cm.py @@ -275,6 +275,13 @@ def to_rgba(self, x, alpha=None, bytes=False, norm=True): x = ma.asarray(x) if norm: x = self.norm(x) + + np_alpha = ma.asarray(alpha) + if np_alpha.ndim == 1 and np_alpha.shape == x.shape: + rgba = self.cmap(x, bytes=bytes) + rgba[0:, 3] = np_alpha + return rgba + rgba = self.cmap(x, alpha=alpha, bytes=bytes) return rgba diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 5576def9d440..7855f69ff404 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -678,6 +678,11 @@ def set_alpha(self, alpha): ACCEPTS: float or None """ if alpha is not None: + # Check if alpha is an array of matching size + np_alpha = ma.asarray(alpha) + if np_alpha.ndim == 1: + artist.Artist.set_alpha(self, np_alpha) + return try: float(alpha) except TypeError: