code: def find_renderer(fig):
      if hasattr(fig.canvas, "get_renderer"):
          # Some backends, such as TkAgg, have the get_renderer method, which
          # makes this easy.
          renderer = fig.canvas.get_renderer()
      else:
          # Other backends do not have the get_renderer method, so we have a work
          # around to find the renderer.  Print the figure to a temporary file
          # object, and then grab the renderer that was used.
          # (I stole this trick from the matplotlib backend_bases.py
          # print_figure() method.)
          import io
  
          fig.canvas.print_pdf(io.BytesIO())
          renderer = fig._cachedRenderer
      return renderer
  
imports: import matplotlib
  import matplotlib.patches
  from matplotlib import pyplot
label_desc: Use image node_id 2 for calling a global function with example usage: find_renderer(fig) and returns: renderer