qiskit/visualization/state_visualization.py
def _shade_colors(color, normals, lightsource=None):
    """
    Shade *color* using normal vectors given by *normals*.
    *color* can also be an array of the same length as *normals*.
    """
    if lightsource is None:
        # chosen for backwards-compatibility
        lightsource = LightSource(azdeg=225, altdeg=19.4712)

    shade = np.array([np.dot(n / proj3d.mod(n), lightsource.direction)
                      if proj3d.mod(n) else np.nan
                      for n in normals])
    mask = ~np.isnan(shade)

    if mask.any():
        norm = Normalize(min(shade[mask]), max(shade[mask]))
        shade[~mask] = min(shade[mask])
        color = mcolors.to_rgba_array(color)
        # shape of color should be (M, 4) (where M is number of faces)
        # shape of shade should be (M,)
        # colors should have final shape of (M, 4)
        alpha = color[:, 3]
        colors = (0.5 + norm(shade)[:, np.newaxis] * 0.5) * color
        colors[:, 3] = alpha
    else:
        colors = np.asanyarray(color).copy()

    return colors
def _shade_colors(color, normals, lightsource=None):
    """
    Shade *color* using normal vectors given by *normals*.
    *color* can also be an array of the same length as *normals*.
    """
    if lightsource is None:
        # chosen for backwards-compatibility
        lightsource = LightSource(azdeg=225, altdeg=19.4712)

    shade = np.array([np.dot(n / proj3d.mod(n), lightsource.direction)
                      if proj3d.mod(n) else np.nan
                      for n in normals])
    mask = ~np.isnan(shade)

    if mask.any():
        norm = Normalize(min(shade[mask]), max(shade[mask]))
        shade[~mask] = min(shade[mask])
        color = mcolors.to_rgba_array(color)
        # shape of color should be (M, 4) (where M is number of faces)
        # shape of shade should be (M,)
        # colors should have final shape of (M, 4)
        alpha = color[:, 3]
        colors = (0.5 + norm(shade)[:, np.newaxis] * 0.5) * color
        colors[:, 3] = alpha
    else:
        colors = np.asanyarray(color).copy()

    return colors
def _shade_colors ( color , normals , lightsource = None ) : if lightsource is None : # chosen for backwards-compatibility lightsource = LightSource ( azdeg = 225 , altdeg = 19.4712 ) shade = np . array ( [ np . dot ( n / proj3d . mod ( n ) , lightsource . direction ) if proj3d . mod ( n ) else np . nan for n in normals ] ) mask = ~ np . isnan ( shade ) if mask . any ( ) : norm = Normalize ( min ( shade [ mask ] ) , max ( shade [ mask ] ) ) shade [ ~ mask ] = min ( shade [ mask ] ) color = mcolors . to_rgba_array ( color ) # shape of color should be (M, 4) (where M is number of faces) # shape of shade should be (M,) # colors should have final shape of (M, 4) alpha = color [ : , 3 ] colors = ( 0.5 + norm ( shade ) [ : , np . newaxis ] * 0.5 ) * color colors [ : , 3 ] = alpha else : colors = np . asanyarray ( color ) . copy ( ) return colors
Shade *color* using normal vectors given by *normals*.
    *color* can also be an array of the same length as *normals*.
Shade * color * using normal vectors given by * normals * . * color * can also be an array of the same length as * normals * .