class_docstr: Exporter used to render data from matplotlib, either to a stream
  or directly to file.
  
  The __call__ method renders an HoloViews component to raw data of
  a specified matplotlib format.  The save method is the
  corresponding method for saving a HoloViews objects to disk.
  
  The save_fig and save_anim methods are used to save matplotlib
  figure and animation objects. These match the two primary return
  types of plotting class implemented with matplotlib.
class_docstr_tok: ["Exporter","used","to","render","data","from","matplotlib",",","either","to","a","stream","or","directly","to","file",".","The","__call__","method","renders","an","HoloViews","component","to","raw","data","of","a","specified","matplotlib","format",".","The","save","method","is","the","corresponding","method","for","saving","a","HoloViews","objects","to","disk",".","The","save_fig","and","save_anim","methods","are","used","to","save","matplotlib","figure","and","animation","objects",".","These","match","the","two","primary","return","types","of","plotting","class","implemented","with","matplotlib","."]
docstr: Render matplotlib figure object and return the corresponding
  data.  If as_script is True, the content will be split in an
  HTML and a JS component.
  
  Similar to IPython.core.pylabtools.print_figure but without
  any IPython dependency.
docstr_tok: ["Render","matplotlib","figure","object","and","return","the","corresponding","data",".","If","as_script","is","True",",","the","content","will","be","split","in","an","HTML","and","a","JS","component",".","Similar","to","IPython.core.pylabtools.print_figure","but","without","any","IPython","dependency","."]
code: def _figure_data(
      self, plot, fmt, bbox_inches="tight", as_script=False, **kwargs
  ):
      """
      Render matplotlib figure object and return the corresponding
      data.  If as_script is True, the content will be split in an
      HTML and a JS component.
  
      Similar to IPython.core.pylabtools.print_figure but without
      any IPython dependency.
      """
      if fmt in ["gif", "mp4", "webm"]:
          with mpl.rc_context(rc=plot.fig_rcparams):
              anim = plot.anim(fps=self.fps)
          data = self._anim_data(anim, fmt)
      else:
          fig = plot.state
  
          traverse_fn = lambda x: x.handles.get(
              "bbox_extra_artists", None
          )
          extra_artists = list(
              chain.from_iterable(
                  artists
                  for artists in plot.traverse(traverse_fn)
                  if artists is not None
              )
          )
  
          kw = dict(
              format=fmt,
              facecolor=fig.get_facecolor(),
              edgecolor=fig.get_edgecolor(),
              dpi=self.dpi,
              bbox_inches=bbox_inches,
              bbox_extra_artists=extra_artists,
          )
          kw.update(kwargs)
  
          # Attempts to precompute the tight bounding box
          try:
              kw = self._compute_bbox(fig, kw)
          except Exception:
              pass
          bytes_io = BytesIO()
          fig.canvas.print_figure(bytes_io, **kw)
          data = bytes_io.getvalue()
  
      if as_script:
          b64 = base64.b64encode(data).decode("utf-8")
          (mime_type, tag) = MIME_TYPES[fmt], HTML_TAGS[fmt]
          src = HTML_TAGS["base64"].format(mime_type=mime_type, b64=b64)
          html = tag.format(src=src, mime_type=mime_type, css="")
          return html
      if fmt == "svg":
          data = data.decode("utf-8")
      return data
  
imports: import base64
  import os
  from contextlib import contextmanager
  from io import BytesIO
  from itertools import chain
  from tempfile import NamedTemporaryFile
  import matplotlib
  import param
  from matplotlib import pyplot
  from param.parameterized import bothmethod
  from ...core import HoloMap
  from ...core.options import Store
  from ..renderer import HTML_TAGS, MIME_TYPES, Renderer
  from .util import get_old_rcparams, get_tight_bbox
label_desc: Use image node_id 4 for calling the MPLRenderer obj's underlying member method code with example usage: obj._figure_data(plot, fmt, bbox_inches, as_script) and returns: data, html