code: def plot_imshow_with_labels(ax, data, extent, origin, xlim, ylim):
      """Actually run ``imshow()`` and add extent and index labels."""
      im = ax.imshow(data, origin=origin, extent=extent)
  
      # extent labels (left, right, bottom, top)
      left, right, bottom, top = im.get_extent()
      if xlim is None or top > bottom:
          upper_string, lower_string = "top", "bottom"
      else:
          upper_string, lower_string = "bottom", "top"
      if ylim is None or left < right:
          port_string, starboard_string = "left", "right"
          inverted_xindex = False
      else:
          port_string, starboard_string = "right", "left"
          inverted_xindex = True
      bbox_kwargs = {"fc": "w", "alpha": 0.75, "boxstyle": "round4"}
      ann_kwargs = {
          "xycoords": "axes fraction",
          "textcoords": "offset points",
          "bbox": bbox_kwargs,
      }
      ax.annotate(
          upper_string,
          xy=(0.5, 1),
          xytext=(0, -1),
          ha="center",
          va="top",
          **ann_kwargs,
      )
      ax.annotate(
          lower_string,
          xy=(0.5, 0),
          xytext=(0, 1),
          ha="center",
          va="bottom",
          **ann_kwargs,
      )
      ax.annotate(
          port_string,
          xy=(0, 0.5),
          xytext=(1, 0),
          ha="left",
          va="center",
          rotation=90,
          **ann_kwargs,
      )
      ax.annotate(
          starboard_string,
          xy=(1, 0.5),
          xytext=(-1, 0),
          ha="right",
          va="center",
          rotation=-90,
          **ann_kwargs,
      )
      ax.set_title(f"origin: {origin}")
  
      # index labels
      for index in ["[0, 0]", "[0, N']", "[M', 0]", "[M', N']"]:
          tx, ty, halign = get_index_label_pos(
              index, extent, origin, inverted_xindex
          )
          facecolor = get_color(index, data, im.get_cmap())
          ax.text(
              tx,
              ty,
              index,
              color="white",
              ha=halign,
              va="center",
              bbox={"boxstyle": "square", "facecolor": facecolor},
          )
      if xlim:
          ax.set_xlim(*xlim)
      if ylim:
          ax.set_ylim(*ylim)
  
file_path: matplotlib/galleries/users_explain/artists/imshow_extent.py
imports: import matplotlib.pyplot
  import numpy
  from matplotlib.gridspec import GridSpec
label_desc: Use image node_id 6 for calling a global function with example usage: plot_imshow_with_labels(ax, data, extent, origin, xlim, ylim) without return types