code: def generate_function(name, called_fullname, template, **kwargs):
      """
      Create a wrapper function *pyplot_name* calling *call_name*.
  
      Parameters
      ----------
      name : str
          The function to be created.
      called_fullname : str
          The method to be wrapped in the format ``"Class.method"``.
      template : str
          The template to be used. The template must contain {}-style format
          placeholders. The following placeholders are filled in:
  
          - name: The function name.
          - signature: The function signature (including parentheses).
          - called_name: The name of the called function.
          - call: Parameters passed to *called_name* (including parentheses).
  
      **kwargs
          Additional parameters are passed to ``template.format()``.
      """
      # Get signature of wrapped function.
      class_name, called_name = called_fullname.split(".")
      class_ = {"Axes": Axes, "Figure": Figure}[class_name]
  
      meth = getattr(class_, called_name)
      decorator = _api.deprecation.DECORATORS.get(meth)
      # Generate the wrapper with the non-kwonly signature, as it will get
      # redecorated with make_keyword_only by _copy_docstring_and_deprecators.
      if decorator and decorator.func is _api.make_keyword_only:
          meth = meth.__wrapped__
  
      annotated_trees = get_ast_mro_trees(class_)
      signature = get_matching_signature(meth, annotated_trees)
  
      # Replace self argument.
      params = list(signature.parameters.values())[1:]
      has_return_value = str(signature.return_annotation) != "None"
      signature = str(
          signature.replace(
              parameters=[
                  param.replace(default=value_formatter(param.default))
                  if param.default is not param.empty
                  else param
                  for param in params
              ]
          )
      )
      # How to call the wrapped function.
      call = (
          "("
          + ", ".join(
              (
                  # Pass "intended-as-positional" parameters positionally to avoid
                  # forcing third-party subclasses to reproduce the parameter names.
                  "{0}"
                  if param.kind in [Parameter.POSITIONAL_OR_KEYWORD]
                  and param.default is Parameter.empty
                  else
                  # Only pass the data kwarg if it is actually set, to avoid forcing
                  # third-party subclasses to support it.
                  '**({{"data": data}} if data is not None else {{}})'
                  if param.name == "data"
                  else "{0}={0}"
                  if param.kind
                  in [
                      Parameter.POSITIONAL_OR_KEYWORD,
                      Parameter.KEYWORD_ONLY,
                  ]
                  else "{0}"
                  if param.kind is Parameter.POSITIONAL_ONLY
                  else "*{0}"
                  if param.kind is Parameter.VAR_POSITIONAL
                  else "**{0}"
                  if param.kind is Parameter.VAR_KEYWORD
                  else None
              ).format(param.name)
              for param in params
          )
          + ")"
      )
      return_statement = "return " if has_return_value else ""
      # Bail out in case of name collision.
      for reserved in ("gca", "gci", "gcf", "__ret"):
          if reserved in params:
              raise ValueError(
                  f"Method {called_fullname} has kwarg named {reserved}"
              )
  
      return template.format(
          name=name,
          called_name=called_name,
          signature=signature,
          call=call,
          return_statement=return_statement,
          **kwargs,
      )
  
imports: import ast
  from enum import Enum
  import functools
  import inspect
  from inspect import Parameter
  from pathlib import Path
  import sys
  import subprocess
  import numpy
  from matplotlib import _api, mlab
  from matplotlib.axes import Axes
  from matplotlib.backend_bases import MouseButton
  from matplotlib.figure import Figure
label_desc: Use image node_id 2 for calling a global function with example usage: generate_function(name, called_fullname, template) and returns: template