code: def apply_alpha(
      colors, alpha, elem_list, cmap=None, vmin=None, vmax=None
  ):
      """Apply an alpha (or list of alphas) to the colors provided.
  
      Parameters
      ----------
  
      colors : color string or array of floats (default='r')
          Color of element. Can be a single color format string,
          or a sequence of colors with the same length as nodelist.
          If numeric values are specified they will be mapped to
          colors using the cmap and vmin,vmax parameters.  See
          matplotlib.scatter for more details.
  
      alpha : float or array of floats
          Alpha values for elements. This can be a single alpha value, in
          which case it will be applied to all the elements of color. Otherwise,
          if it is an array, the elements of alpha will be applied to the colors
          in order (cycling through alpha multiple times if necessary).
  
      elem_list : array of networkx objects
          The list of elements which are being colored. These could be nodes,
          edges or labels.
  
      cmap : matplotlib colormap
          Color map for use if colors is a list of floats corresponding to points
          on a color mapping.
  
      vmin, vmax : float
          Minimum and maximum values for normalizing colors if a colormap is used
  
      Returns
      -------
  
      rgba_colors : numpy ndarray
          Array containing RGBA format values for each of the node colours.
  
      """
      from itertools import cycle, islice
  
      import matplotlib as mpl
      import matplotlib.cm  # call as mpl.cm
      import matplotlib.colors  # call as mpl.colors
      import numpy as np
  
      # If we have been provided with a list of numbers as long as elem_list,
      # apply the color mapping.
      if len(colors) == len(elem_list) and isinstance(
          colors[0], Number
      ):
          mapper = mpl.cm.ScalarMappable(cmap=cmap)
          mapper.set_clim(vmin, vmax)
          rgba_colors = mapper.to_rgba(colors)
      # Otherwise, convert colors to matplotlib's RGB using the colorConverter
      # object.  These are converted to numpy ndarrays to be consistent with the
      # to_rgba method of ScalarMappable.
      else:
          try:
              rgba_colors = np.array(
                  [mpl.colors.colorConverter.to_rgba(colors)]
              )
          except ValueError:
              rgba_colors = np.array(
                  [
                      mpl.colors.colorConverter.to_rgba(color)
                      for color in colors
                  ]
              )
      # Set the final column of the rgba_colors to have the relevant alpha values
      try:
          # If alpha is longer than the number of colors, resize to the number of
          # elements.  Also, if rgba_colors.size (the number of elements of
          # rgba_colors) is the same as the number of elements, resize the array,
          # to avoid it being interpreted as a colormap by scatter()
          if len(alpha) > len(rgba_colors) or rgba_colors.size == len(
              elem_list
          ):
              rgba_colors = np.resize(rgba_colors, (len(elem_list), 4))
              rgba_colors[1:, 0] = rgba_colors[0, 0]
              rgba_colors[1:, 1] = rgba_colors[0, 1]
              rgba_colors[1:, 2] = rgba_colors[0, 2]
          rgba_colors[:, 3] = list(
              islice(cycle(alpha), len(rgba_colors))
          )
      except TypeError:
          rgba_colors[:, -1] = alpha
      return rgba_colors
  
file_path: networkx/networkx/drawing/nx_pylab.py
imports: from numbers import Number
  import networkx
  from networkx.drawing.layout import circular_layout, kamada_kawai_layout, planar_layout, random_layout, shell_layout, spectral_layout, spring_layout
label_desc: Use image node_id 14 for calling a global function with example usage: apply_alpha(colors, alpha, elem_list, cmap, vmin, vmax) and returns: rgba_colors