From 9b5a0aba8aa7b7bc276eef8562607dd88af706ed Mon Sep 17 00:00:00 2001 From: Ricardo Peres Date: Thu, 16 Mar 2023 14:01:37 +0100 Subject: [PATCH 1/4] Fix alpha bug on 3D PathCollection plots. --- lib/mpl_toolkits/mplot3d/art3d.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 39805142a5ac..03402a2db04e 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -769,7 +769,12 @@ def _maybe_depth_shade_and_sort_colors(self, color_array): ) if len(color_array) > 1: color_array = color_array[self._z_markers_idx] - return mcolors.to_rgba_array(color_array, self._alpha) + + if self._alpha is not None: + converted_alphas = color_array[:,3] * self._alpha + else: + converted_alphas = color_array[:,3] + return mcolors.to_rgba_array(color_array, converted_alphas) def get_facecolor(self): return self._maybe_depth_shade_and_sort_colors(super().get_facecolor()) From a9412140ffa41674a1da6dd66d7759ec40659516 Mon Sep 17 00:00:00 2001 From: Ricardo Peres Date: Thu, 16 Mar 2023 14:23:45 +0100 Subject: [PATCH 2/4] Fix flake8 linting errors --- lib/mpl_toolkits/mplot3d/art3d.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 03402a2db04e..abda2c0eeff8 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -769,11 +769,11 @@ def _maybe_depth_shade_and_sort_colors(self, color_array): ) if len(color_array) > 1: color_array = color_array[self._z_markers_idx] - + if self._alpha is not None: - converted_alphas = color_array[:,3] * self._alpha + converted_alphas = color_array[:, 3] * self._alpha else: - converted_alphas = color_array[:,3] + converted_alphas = color_array[:, 3] return mcolors.to_rgba_array(color_array, converted_alphas) def get_facecolor(self): From 09d2179cc56625faf28458c9d8f4b94687a72e2a Mon Sep 17 00:00:00 2001 From: Ricardo Peres Date: Fri, 30 Jun 2023 18:53:38 +0200 Subject: [PATCH 3/4] Handle RGB instead of RGBA case. --- lib/mpl_toolkits/mplot3d/art3d.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index abda2c0eeff8..bb0fc1f57ab9 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -770,6 +770,9 @@ def _maybe_depth_shade_and_sort_colors(self, color_array): if len(color_array) > 1: color_array = color_array[self._z_markers_idx] + if color_array.shape[1] == 3: # color_array is RGB instead of RGBA + return mcolors.to_rgba_array(color_array, self._alpha) + if self._alpha is not None: converted_alphas = color_array[:, 3] * self._alpha else: From 69ad517749020ad090dc701a30c5b70e6ec0ba35 Mon Sep 17 00:00:00 2001 From: Ricardo Peres Date: Fri, 30 Jun 2023 18:59:22 +0200 Subject: [PATCH 4/4] Clean main if clause. --- lib/mpl_toolkits/mplot3d/art3d.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index bb0fc1f57ab9..3975962522c4 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -773,10 +773,12 @@ def _maybe_depth_shade_and_sort_colors(self, color_array): if color_array.shape[1] == 3: # color_array is RGB instead of RGBA return mcolors.to_rgba_array(color_array, self._alpha) - if self._alpha is not None: - converted_alphas = color_array[:, 3] * self._alpha - else: - converted_alphas = color_array[:, 3] + converted_alphas = ( + color_array[:, 3] * self._alpha + if self._alpha is not None + else color_array[:, 3] + ) + return mcolors.to_rgba_array(color_array, converted_alphas) def get_facecolor(self):