qiskit/visualization/state_visualization.py
def generate_facecolors(x, y, z, dx, dy, dz, color):
    """Generates shaded facecolors for shaded bars.
    This is here to work around a Matplotlib bug
    where alpha does not work in Bar3D.
    Args:
        x (array_like): The x- coordinates of the anchor point of the bars.
        y (array_like): The y- coordinates of the anchor point of the bars.
        z (array_like): The z- coordinates of the anchor point of the bars.
        dx (array_like): Width of bars.
        dy (array_like): Depth of bars.
        dz (array_like): Height of bars.
        color (array_like): sequence of valid color specifications, optional
    Returns:
        list: Shaded colors for bars.
    """
    cuboid = np.array([
        # -z
        (
            (0, 0, 0),
            (0, 1, 0),
            (1, 1, 0),
            (1, 0, 0),
        ),
        # +z
        (
            (0, 0, 1),
            (1, 0, 1),
            (1, 1, 1),
            (0, 1, 1),
        ),
        # -y
        (
            (0, 0, 0),
            (1, 0, 0),
            (1, 0, 1),
            (0, 0, 1),
        ),
        # +y
        (
            (0, 1, 0),
            (0, 1, 1),
            (1, 1, 1),
            (1, 1, 0),
        ),
        # -x
        (
            (0, 0, 0),
            (0, 0, 1),
            (0, 1, 1),
            (0, 1, 0),
        ),
        # +x
        (
            (1, 0, 0),
            (1, 1, 0),
            (1, 1, 1),
            (1, 0, 1),
        ),
    ])

    # indexed by [bar, face, vertex, coord]
    polys = np.empty(x.shape + cuboid.shape)
    # handle each coordinate separately
    for i, p, dp in [(0, x, dx), (1, y, dy), (2, z, dz)]:
        p = p[..., np.newaxis, np.newaxis]
        dp = dp[..., np.newaxis, np.newaxis]
        polys[..., i] = p + dp * cuboid[..., i]

    # collapse the first two axes
    polys = polys.reshape((-1,) + polys.shape[2:])

    facecolors = []
    if len(color) == len(x):
        # bar colors specified, need to expand to number of faces
        for c in color:
            facecolors.extend([c] * 6)
    else:
        # a single color specified, or face colors specified explicitly
        facecolors = list(mcolors.to_rgba_array(color))
        if len(facecolors) < len(x):
            facecolors *= (6 * len(x))

    normals = _generate_normals(polys)
    return _shade_colors(facecolors, normals)
def generate_facecolors(x, y, z, dx, dy, dz, color):
    """Generates shaded facecolors for shaded bars.
    This is here to work around a Matplotlib bug
    where alpha does not work in Bar3D.
    Args:
        x (array_like): The x- coordinates of the anchor point of the bars.
        y (array_like): The y- coordinates of the anchor point of the bars.
        z (array_like): The z- coordinates of the anchor point of the bars.
        dx (array_like): Width of bars.
        dy (array_like): Depth of bars.
        dz (array_like): Height of bars.
        color (array_like): sequence of valid color specifications, optional
    Returns:
        list: Shaded colors for bars.
    """
    cuboid = np.array([
        # -z
        (
            (0, 0, 0),
            (0, 1, 0),
            (1, 1, 0),
            (1, 0, 0),
        ),
        # +z
        (
            (0, 0, 1),
            (1, 0, 1),
            (1, 1, 1),
            (0, 1, 1),
        ),
        # -y
        (
            (0, 0, 0),
            (1, 0, 0),
            (1, 0, 1),
            (0, 0, 1),
        ),
        # +y
        (
            (0, 1, 0),
            (0, 1, 1),
            (1, 1, 1),
            (1, 1, 0),
        ),
        # -x
        (
            (0, 0, 0),
            (0, 0, 1),
            (0, 1, 1),
            (0, 1, 0),
        ),
        # +x
        (
            (1, 0, 0),
            (1, 1, 0),
            (1, 1, 1),
            (1, 0, 1),
        ),
    ])

    # indexed by [bar, face, vertex, coord]
    polys = np.empty(x.shape + cuboid.shape)
    # handle each coordinate separately
    for i, p, dp in [(0, x, dx), (1, y, dy), (2, z, dz)]:
        p = p[..., np.newaxis, np.newaxis]
        dp = dp[..., np.newaxis, np.newaxis]
        polys[..., i] = p + dp * cuboid[..., i]

    # collapse the first two axes
    polys = polys.reshape((-1,) + polys.shape[2:])

    facecolors = []
    if len(color) == len(x):
        # bar colors specified, need to expand to number of faces
        for c in color:
            facecolors.extend([c] * 6)
    else:
        # a single color specified, or face colors specified explicitly
        facecolors = list(mcolors.to_rgba_array(color))
        if len(facecolors) < len(x):
            facecolors *= (6 * len(x))

    normals = _generate_normals(polys)
    return _shade_colors(facecolors, normals)
def generate_facecolors ( x , y , z , dx , dy , dz , color ) : cuboid = np . array ( [ # -z ( ( 0 , 0 , 0 ) , ( 0 , 1 , 0 ) , ( 1 , 1 , 0 ) , ( 1 , 0 , 0 ) , ) , # +z ( ( 0 , 0 , 1 ) , ( 1 , 0 , 1 ) , ( 1 , 1 , 1 ) , ( 0 , 1 , 1 ) , ) , # -y ( ( 0 , 0 , 0 ) , ( 1 , 0 , 0 ) , ( 1 , 0 , 1 ) , ( 0 , 0 , 1 ) , ) , # +y ( ( 0 , 1 , 0 ) , ( 0 , 1 , 1 ) , ( 1 , 1 , 1 ) , ( 1 , 1 , 0 ) , ) , # -x ( ( 0 , 0 , 0 ) , ( 0 , 0 , 1 ) , ( 0 , 1 , 1 ) , ( 0 , 1 , 0 ) , ) , # +x ( ( 1 , 0 , 0 ) , ( 1 , 1 , 0 ) , ( 1 , 1 , 1 ) , ( 1 , 0 , 1 ) , ) , ] ) # indexed by [bar, face, vertex, coord] polys = np . empty ( x . shape + cuboid . shape ) # handle each coordinate separately for i , p , dp in [ ( 0 , x , dx ) , ( 1 , y , dy ) , ( 2 , z , dz ) ] : p = p [ ... , np . newaxis , np . newaxis ] dp = dp [ ... , np . newaxis , np . newaxis ] polys [ ... , i ] = p + dp * cuboid [ ... , i ] # collapse the first two axes polys = polys . reshape ( ( - 1 , ) + polys . shape [ 2 : ] ) facecolors = [ ] if len ( color ) == len ( x ) : # bar colors specified, need to expand to number of faces for c in color : facecolors . extend ( [ c ] * 6 ) else : # a single color specified, or face colors specified explicitly facecolors = list ( mcolors . to_rgba_array ( color ) ) if len ( facecolors ) < len ( x ) : facecolors *= ( 6 * len ( x ) ) normals = _generate_normals ( polys ) return _shade_colors ( facecolors , normals )
Generates shaded facecolors for shaded bars.
    This is here to work around a Matplotlib bug
    where alpha does not work in Bar3D.
    Args:
        x (array_like): The x- coordinates of the anchor point of the bars.
        y (array_like): The y- coordinates of the anchor point of the bars.
        z (array_like): The z- coordinates of the anchor point of the bars.
        dx (array_like): Width of bars.
        dy (array_like): Depth of bars.
        dz (array_like): Height of bars.
        color (array_like): sequence of valid color specifications, optional
    Returns:
        list: Shaded colors for bars.
Generates shaded facecolors for shaded bars . This is here to work around a Matplotlib bug where alpha does not work in Bar3D . Args : x ( array_like ) : The x - coordinates of the anchor point of the bars . y ( array_like ) : The y - coordinates of the anchor point of the bars . z ( array_like ) : The z - coordinates of the anchor point of the bars . dx ( array_like ) : Width of bars . dy ( array_like ) : Depth of bars . dz ( array_like ) : Height of bars . color ( array_like ) : sequence of valid color specifications optional Returns : list : Shaded colors for bars .