code: def show_hist(
      source,
      bins=10,
      masked=True,
      title="Histogram",
      ax=None,
      label=None,
      range=None,
      **kwargs,
  ):
      """Easily display a histogram with matplotlib.
  
      Parameters
      ----------
      source : array or dataset object opened in 'r' mode or Band or tuple(dataset, bidx)
          Input data to display.
          The first three arrays in multi-dimensional
          arrays are plotted as red, green, and blue.
      bins : int, optional
          Compute histogram across N bins.
      masked : bool, optional
          When working with a `rasterio.Band()` object, specifies if the data
          should be masked on read.
      title : str, optional
          Title for the figure.
      ax : matplotlib.axes.Axes, optional
          The raster will be added to this axes if passed.
      label : str, optional
          String, or list of strings. If passed, matplotlib will use this label list.
          Otherwise, a default label list will be automatically created
      range : list, optional
          List of `[min, max]` values. If passed, matplotlib will use this range.
          Otherwise, a default range will be automatically created
      **kwargs : optional keyword arguments
          These will be passed to the :meth:`matplotlib.axes.Axes.hist` method.
      """
      plt = get_plt()
  
      if isinstance(source, DatasetReader):
          arr = source.read(masked=masked)
      elif isinstance(source, (tuple, rasterio.Band)):
          arr = source[0].read(source[1], masked=masked)
      else:
          arr = source
  
      if range is None:
          # The histogram is computed individually for each 'band' in the array
          # so we need the overall min/max to constrain the plot
          range = np.nanmin(arr), np.nanmax(arr)
  
      if len(arr.shape) == 2:
          arr = np.expand_dims(arr.flatten(), 0).T
          colors = ["gold"]
      else:
          arr = arr.reshape(arr.shape[0], -1).T
          colors = [
              "red",
              "green",
              "blue",
              "violet",
              "gold",
              "saddlebrown",
          ]
  
      # The goal is to provide a curated set of colors for working with
      # smaller datasets and let matplotlib define additional colors when
      # working with larger datasets.
      if arr.shape[-1] > len(colors):
          n = arr.shape[-1] - len(colors)
          colors.extend(
              np.ndarray.tolist(
                  plt.get_cmap("Accent")(np.linspace(0, 1, n))
              )
          )
      else:
          colors = colors[: arr.shape[-1]]
  
      # if the user used the label argument, pass them drectly to matplotlib
      if label:
          labels = label
      # else, create default labels
      else:
          # If a rasterio.Band() is given make sure the proper index is displayed
          # in the legend.
          if isinstance(source, (tuple, rasterio.Band)):
              labels = [str(source[1])]
          else:
              labels = [str(i + 1) for i in builtins.range(len(arr))]
  
      if ax:
          show = False
      else:
          show = True
          ax = plt.gca()
  
      fig = ax.get_figure()
  
      ax.hist(
          arr,
          bins=bins,
          color=colors,
          label=labels,
          range=range,
          **kwargs,
      )
  
      ax.legend(loc="upper right")
      ax.set_title(title, fontweight="bold")
      ax.grid(True)
      ax.set_xlabel("DN")
      ax.set_ylabel("Frequency")
      if show:
          plt.show()
  
file_path: rasterio/rasterio/plot.py
imports: import builtins
  from collections import OrderedDict
  import logging
  import numpy
  import rasterio
  from rasterio.io import DatasetReader
  from rasterio.transform import guard_transform
label_desc: Use image node_id 6 for calling a global function with example usage: show_hist(source, bins, masked, title, ax, label, range) without return types