code: def mpl_to_plotly(
      fig, resize=False, strip_style=False, verbose=False
  ):
      """Convert a matplotlib figure to plotly dictionary and send.
  
      All available information about matplotlib visualizations are stored
      within a matplotlib.figure.Figure object. You can create a plot in python
      using matplotlib, store the figure object, and then pass this object to
      the fig_to_plotly function. In the background, mplexporter is used to
      crawl through the mpl figure object for appropriate information. This
      information is then systematically sent to the PlotlyRenderer which
      creates the JSON structure used to make plotly visualizations. Finally,
      these dictionaries are sent to plotly and your browser should open up a
      new tab for viewing! Optionally, if you're working in IPython, you can
      set notebook=True and the PlotlyRenderer will call plotly.iplot instead
      of plotly.plot to have the graph appear directly in the IPython notebook.
  
      Note, this function gives the user access to a simple, one-line way to
      render an mpl figure in plotly. If you need to trouble shoot, you can do
      this step manually by NOT running this fuction and entereing the following:
  
      ===========================================================================
      from plotly.matplotlylib import mplexporter, PlotlyRenderer
  
      # create an mpl figure and store it under a varialble 'fig'
  
      renderer = PlotlyRenderer()
      exporter = mplexporter.Exporter(renderer)
      exporter.run(fig)
      ===========================================================================
  
      You can then inspect the JSON structures by accessing these:
  
      renderer.layout -- a plotly layout dictionary
      renderer.data -- a list of plotly data dictionaries
      """
      matplotlylib = optional_imports.get_module("plotly.matplotlylib")
      if matplotlylib:
          renderer = matplotlylib.PlotlyRenderer()
          matplotlylib.Exporter(renderer).run(fig)
          if resize:
              renderer.resize()
          if strip_style:
              renderer.strip_style()
          if verbose:
              print(renderer.msg)
          return renderer.plotly_fig
      else:
          warnings.warn(
              "To use Plotly's matplotlylib functionality, you'll need to have "
              "matplotlib successfully installed with all of its dependencies. "
              "You're getting this error because matplotlib or one of its "
              "dependencies doesn't seem to be installed correctly."
          )
  
imports: from __future__ import absolute_import
  import json
  import warnings
  import six
  import re
  import os
  from plotly import exceptions, optional_imports
  from plotly.files import PLOTLY_DIR
label_desc: Use image node_id 2 for calling a global function with example usage: mpl_to_plotly(fig, resize, strip_style, verbose) and returns: renderer