code: def patch_matplotlib():
      # only once
      if PatchedMatplotlib._patched_original_plot is not None:
          return True
      # make sure we only patch once
      PatchedMatplotlib._patched_original_plot = False
  
      # noinspection PyBroadException
      try:
          # we support matplotlib version 2.0.0 and above
          import matplotlib
  
          PatchedMatplotlib._update_matplotlib_version()
          if PatchedMatplotlib._matplot_major_version < 2:
              LoggerRoot.get_base_logger().warning(
                  "matplotlib binding supports version 2.0 and above, found version {}".format(
                      matplotlib.__version__
                  )
              )
              PatchedMatplotlib._patched_original_plot = False
              return False
  
          if running_remotely():
              # disable GUI backend - make headless
              matplotlib.rcParams["backend"] = "agg"
              import matplotlib.pyplot
  
              matplotlib.pyplot.switch_backend("agg")
          import matplotlib.pyplot as plt
          import matplotlib.figure as figure
  
          if six.PY2:
              PatchedMatplotlib._patched_original_plot = staticmethod(
                  plt.show
              )
              PatchedMatplotlib._patched_original_imshow = staticmethod(
                  plt.imshow
              )
              PatchedMatplotlib._patched_original_figure = staticmethod(
                  figure.Figure.show
              )
              PatchedMatplotlib._patched_original_savefig = (
                  staticmethod(figure.Figure.savefig)
              )
          else:
              PatchedMatplotlib._patched_original_plot = plt.show
              PatchedMatplotlib._patched_original_imshow = plt.imshow
              PatchedMatplotlib._patched_original_figure = (
                  figure.Figure.show
              )
              PatchedMatplotlib._patched_original_savefig = (
                  figure.Figure.savefig
              )
  
          # noinspection PyBroadException
          try:
              import matplotlib.pylab as pltlab
  
              if plt.show == pltlab.show:
                  pltlab.show = PatchedMatplotlib.patched_show
              if plt.imshow == pltlab.imshow:
                  pltlab.imshow = PatchedMatplotlib.patched_imshow
          except Exception:
              pass
          plt.show = PatchedMatplotlib.patched_show
          figure.Figure.show = PatchedMatplotlib.patched_figure_show
          sys.modules[
              "matplotlib"
          ].pyplot.imshow = PatchedMatplotlib.patched_imshow
          sys.modules[
              "matplotlib"
          ].figure.Figure.savefig = PatchedMatplotlib.patched_savefig
          # patch plotly so we know it failed us.
          from ..utilities.plotlympl import renderer
  
          # noinspection PyProtectedMember
          renderer.warnings = PatchedMatplotlib._PatchWarnings()
  
      except Exception:
          return False
  
      # patch IPython matplotlib inline mode
      # noinspection PyBroadException
      try:
          if "IPython" in sys.modules:
              from IPython import get_ipython
  
              ip = get_ipython()
              if ip and matplotlib.is_interactive():
                  # instead of hooking ipython, we should hook the matplotlib
                  import matplotlib.pyplot as plt
  
                  PatchedMatplotlib.__patched_original_draw_all = (
                      plt.draw_all
                  )
                  plt.draw_all = PatchedMatplotlib.__patched_draw_all
                  # ip.events.register('post_execute', PatchedMatplotlib.ipython_post_execute_hook)
      except Exception:
          pass
  
      # update api version
      PatchedMatplotlib._update_matplotlib_image_support()
  
      # load plotly
      PatchedMatplotlib._update_plotly_renderers()
  
      return True
  
imports: import sys
  import threading
  from copy import deepcopy
  from tempfile import mkstemp
  import six
  from six import BytesIO
  from .import_bind import PostImportHookPatching
  from ..config import running_remotely
  from ..debugging.log import LoggerRoot
  from ..utilities.resource_monitor import ResourceMonitor
label_desc: Use image node_id 2 for calling the PatchedMatplotlib obj's underlying member method code with example usage: obj.patch_matplotlib() and returns: True, True, False, False