code: def add_segmented_colorbar(da, colors, direction):
      """
      Add 'non-rastered' colorbar to DrawingArea
      """
      from matplotlib.collections import PolyCollection
  
      nbreak = len(colors)
      if direction == "vertical":
          linewidth = da.height / nbreak
          verts = []
          x1, x2 = 0, da.width
          for i in range(nbreak):
              y1 = i * linewidth
              y2 = y1 + linewidth
              verts.append(((x1, y1), (x1, y2), (x2, y2), (x2, y1)))
      else:
          linewidth = da.width / nbreak
          verts = []
          y1, y2 = 0, da.height
          for i in range(nbreak):
              x1 = i * linewidth
              x2 = x1 + linewidth
              verts.append(((x1, y1), (x1, y2), (x2, y2), (x2, y1)))
  
      coll = PolyCollection(
          verts, facecolors=colors, linewidth=0, antialiased=False
      )
      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 2 for calling a global function with example usage: add_segmented_colorbar(da, colors, direction) without return types