code: def add_interpolated_colorbar(da, colors, direction):
      """
      Add 'rastered' colorbar to DrawingArea
      """
      from matplotlib.collections import QuadMesh
      from matplotlib.colors import ListedColormap
  
      # Special case that arises due to not so useful
      # aesthetic mapping.
      if len(colors) == 1:
          colors = [colors[0], colors[0]]
  
      # Number of horizontal egdes(breaks) in the grid
      # No need to create more nbreak than colors, provided
      # no. of colors = no. of breaks = no. of cmap colors
      # the shading does a perfect interpolation
      nbreak = len(colors)
  
      if direction == "vertical":
          mesh_width = 1
          mesh_height = nbreak - 1
          linewidth = da.height / mesh_height
          # Construct rectangular meshgrid
          # The values(Z) at each vertex are just the
          # normalized (onto [0, 1]) vertical distance
          x = np.array([0, da.width])
          y = np.arange(0, nbreak) * linewidth
          X, Y = np.meshgrid(x, y)
          Z = Y / y.max()
      else:
          mesh_width = nbreak - 1
          mesh_height = 1
          linewidth = da.width / mesh_width
          x = np.arange(0, nbreak) * linewidth
          y = np.array([0, da.height])
          X, Y = np.meshgrid(x, y)
          Z = X / x.max()
  
      # As a 3D (mesh_width x mesh_height x 2) coordinates array
      coordinates = np.stack([X, Y], axis=-1)
      cmap = ListedColormap(colors)
      coll = QuadMesh(
          coordinates,
          antialiased=False,
          shading="gouraud",
          linewidth=0,
          cmap=cmap,
          array=Z.ravel(),
      )
      da.add_artist(coll)
  
imports: from __future__ import annotations
  import hashlib
  import typing
  from warnings import warn
  import numpy
  import pandas
  from mizani.bounds import rescale
  from ..exceptions import PlotnineWarning
  from ..mapping.aes import rename_aesthetics
  from ..scales.scale_continuous import scale_continuous
  from .guide import guide
label_desc: Use image node_id 1 for calling a global function with example usage: add_interpolated_colorbar(da, colors, direction) without return types