code: def hist(
      arr,
      colors=["purple"],
      figsize=(12, 12),
      cols=2,
      bins=20,
      title=None,
      xlabel="",
      ylabel="",
      hist_range=None,
      alpha=1,
  ):
      """Plot histogram for each layer in a numpy array.
  
      Parameters
      ----------
      arr : numpy array
          An n-dimensional numpy array from which n histograms will be plotted.
      colors : list (default = ["purple"])
          A list of color values that should either equal the number of bands
          or be a single color.
      figsize : tuple (default = (12, 12))
          The x and y integer dimensions of the output plot.
      cols : int (default = 2)
          The number of columns for plot grid.
      bins : int or list (default = 20)
          The number of bins to generate for the histogram or a list of break
          points for each bin following matplotlib ax.hist documentation.
      title : str or list (optional)
          A list of title values that should either equal the number of bands
          or be empty. A string is accepted for a single dimension array.
      xlabel : str (optional)
          The text to print on the x axis.
      ylabel : str (optional)
          The text to print on the y axis.
      hist_range : tuple (optional)
          The lower and upper range of the bins. Lower and upper outliers are
          ignored. If not provided, range is (x.min(), x.max()).
          Range has no effect if bins is a sequence.
      alpha : float (optional)
          The alpha value for the plot. This will help adjust the transparency
          of the plot to the desired level.
  
      Returns
      ----------
      tuple
  
          fig : figure object
              The figure object associated with the histogram.
          ax or axs : ax or axes object
              The axes object(s) associated with the histogram.
  
      Example
      -------
  
      .. plot::
  
          >>> import matplotlib.pyplot as plt
          >>> import rasterio as rio
          >>> import earthpy.plot as ep
          >>> from earthpy.io import path_to_example
          >>> with rio.open(path_to_example('rmnp-rgb.tif')) as src:
          ...     img_array = src.read()
          >>> ep.hist(img_array,
          ...     colors=['r', 'g', 'b'],
          ...     title=['Red', 'Green', 'Blue'],
          ...     cols=3,
          ...     figsize=(8, 3))
          (<Figure size 800x300 with 3 Axes>, ...)
      """
  
      if title:
          if isinstance(title, str):
              title = [title]
      if colors:
          if isinstance(colors, str):
              colors = [colors]
      if not hist_range:
          hist_range = (np.nanmin(arr), np.nanmax(arr))
  
      # If the arr has a single extra dim, flatten it
      if arr.shape[0] == 1:
          arr = arr.squeeze()
  
      # If the array is 3 dimensional setup grid plotting
      if arr.ndim > 2:
          # Compress the arr if it's masked
          n_layers = arr.shape[0]
          if title and not len(title) == n_layers:
              raise ValueError(
                  "The number of plot titles should be the same "
                  "as the number of raster layers in your array."
              )
          # Calculate the total rows that will be required to plot each band
          plot_rows = int(np.ceil(arr.shape[0] / cols))
          if np.ma.is_masked(arr):
              arrlis = []
              for i in range(arr.shape[0]):
                  # Use compressed to flatten masked arr
                  arrlis.append(arr[i].compressed())
              arr = arrlis
          fig, axs = plt.subplots(
              plot_rows, cols, figsize=figsize, sharex=True, sharey=True
          )
          axs_ravel = axs.ravel()
          for band, ax, i in zip(arr, axs.ravel(), range(n_layers)):
              if len(colors) == 1:
                  the_color = colors[0]
              else:
                  the_color = colors[i]
              ax.hist(
                  band.ravel(),
                  bins=bins,
                  color=the_color,
                  alpha=alpha,
                  range=hist_range,
              )
              if title:
                  ax.set_title(title[i])
              if xlabel:
                  ax.set(xlabel=xlabel)
              if ylabel:
                  ax.set(ylabel=ylabel)
          # Clear additional axis elements
          for ax in axs_ravel[n_layers:]:
              ax.set_axis_off()
  
          return fig, axs
  
      elif arr.ndim <= 2:
          # Test that only one title is provided for a 2-dim array
          if title:
              if len(title) > 1:
                  raise ValueError(
                      "You have one array to plot but more than one title. "
                      "Please provide a single title value."
                  )
  
          # Plot all bands
          if np.ma.is_masked(arr):
              arr_comp = arr.compressed()
          else:
              arr_comp = arr.ravel()
          if not hist_range:
              hist_range = (np.nanmin(arr_comp), np.nanmax(arr_comp))
          fig, ax = plt.subplots(figsize=figsize)
          ax.hist(
              arr_comp,
              range=hist_range,
              bins=bins,
              color=colors[0],
              alpha=alpha,
          )
          if title:
              ax.set(title=title[0])
          if xlabel:
              ax.set(xlabel=xlabel)
          if ylabel:
              ax.set(ylabel=ylabel)
          return fig, ax
  
file_path: earthpy/earthpy/plot.py
imports: import numpy
  import numpy.ma
  import matplotlib.pyplot
  from matplotlib import patches
  from matplotlib.colors import ListedColormap
  from mpl_toolkits.axes_grid1 import make_axes_locatable
  from skimage import exposure
  import earthpy.spatial
label_desc: Use image node_id 6 for calling a global function with example usage: hist(arr, colors, figsize, cols, bins, title, xlabel, ylabel, hist_range, alpha) and returns: fig,  axs, fig,  ax