31
31
from matplotlib .tri .triangulation import Triangulation
32
32
from matplotlib import colors as mcolors
33
33
from matplotlib .colors import Normalize , LightSource
34
+ from matplotlib .cbook ._backports import broadcast_to
34
35
35
36
from . import art3d
36
37
from . import proj3d
@@ -2762,9 +2763,16 @@ def voxels(self, filled, color=None, **kwargs):
2762
2763
to fill
2763
2764
2764
2765
color : array_like
2765
- Either a single value or an array the same shape as filled,
2766
- indicating what color to draw the faces of the voxels. If None,
2767
- plot all voxels in the same color, the next in the color sequence.
2766
+ The color to draw the faces of the voxels. This parameter can be:
2767
+
2768
+ - A single color value, to color all voxels the same color. This
2769
+ can be either a string, or a 1D rgb/rgba array
2770
+ - ``None``, indicating the above with the next color in the
2771
+ sequence
2772
+ - A 3D ndarray of color names, with each item the color for the
2773
+ corresponding voxel. The size must match the voxels.
2774
+ - A 4D ndarray of rgb/rgba data, with the components along the
2775
+ last axis.
2768
2776
2769
2777
Any additional keyword arguments are passed onto
2770
2778
:func:`~mpl_toolkits.mplot3d.art3d.Poly3DCollection`
@@ -2785,15 +2793,18 @@ def voxels(self, filled, color=None, **kwargs):
2785
2793
# handle the color argument
2786
2794
if color is None :
2787
2795
color = self ._get_patches_for_fill .get_next_color ()
2788
- if np .ndim (color ) <= 1 :
2789
- color , _ = np .broadcast_arrays (
2790
- color ,
2791
- filled [np .index_exp [...] + np .index_exp [np .newaxis ] * np .ndim (color )]
2792
- )
2793
- elif np .ndim (color ) < 3 :
2794
- raise ValueError ("Argument color must be at least 3-dimensional" )
2795
- elif np .shape (color )[:3 ] != filled .shape :
2796
- raise ValueError ("Argument color must match the shape of filled, if multidimensional" )
2796
+ if np .ndim (color ) in (0 , 1 ):
2797
+ # single color, like "red" or [1, 0, 0]
2798
+ color = broadcast_to (color , filled .shape + np .shape (color ))
2799
+ elif np .ndim (color ) in (3 , 4 ):
2800
+ # 3D array of strings, or 4D array with last axis rgb
2801
+ if np .shape (color )[:3 ] != filled .shape :
2802
+ raise ValueError (
2803
+ "When multidimensional, color must match the shape of "
2804
+ "filled" )
2805
+ else :
2806
+ raise ValueError ("Invalid color argument" )
2807
+
2797
2808
2798
2809
# always scale to the full array, even if the data is only in the center
2799
2810
self .auto_scale_xyz (
0 commit comments