code: def __init__(self, fig, menuitems):
      self.figure = fig
  
      self.menuitems = menuitems
  
      maxw = max(item.text_bbox.width for item in menuitems)
      maxh = max(item.text_bbox.height for item in menuitems)
      depth = max(-item.text_bbox.y0 for item in menuitems)
  
      x0 = 1
      y0 = 4
  
      width = maxw + 2 * MenuItem.padx
      height = maxh + MenuItem.pady
  
      for item in menuitems:
          left = x0
          bottom = y0 - maxh - MenuItem.pady
  
          item.set_extent(left, bottom, width, height, depth)
  
          fig.artists.append(item)
          y0 -= maxh + MenuItem.pady
  
      fig.canvas.mpl_connect("motion_notify_event", self.on_move)
  
file_path: matplotlib/galleries/examples/widgets/menu.py
imports: from dataclasses import dataclass
  import matplotlib.pyplot
  import matplotlib.artist
  import matplotlib.patches
  from matplotlib.typing import ColorType
label_desc: Use image node_id 1 to create a new Menu object  with example: obj = Menu(fig, menuitems)