docstr: Given a plot instance, an output format and an optional bokeh
  document, return the corresponding data. If as_script is True,
  the content will be split in an HTML and a JS component.
docstr_tok: ["Given","a","plot","instance",",","an","output","format","and","an","optional","bokeh","document",",","return","the","corresponding","data",".","If","as_script","is","True",",","the","content","will","be","split","in","an","HTML","and","a","JS","component","."]
code: def _figure_data(
      self, plot, fmt, doc=None, as_script=False, **kwargs
  ):
      """
      Given a plot instance, an output format and an optional bokeh
      document, return the corresponding data. If as_script is True,
      the content will be split in an HTML and a JS component.
      """
      model = plot.state
      if doc is None:
          doc = plot.document
      else:
          plot.document = doc
  
      for m in model.references():
          m._document = None
  
      doc.theme = self.theme
      doc.add_root(model)
  
      # Bokeh raises warnings about duplicate tools and empty subplots
      # but at the holoviews level these are not issues
      logger = logging.getLogger(bokeh.core.validation.check.__file__)
      logger.disabled = True
  
      data = None
      if fmt == "gif":
          from bokeh.io.export import get_screenshot_as_png
          from bokeh.io.webdriver import webdriver_control
  
          if state.webdriver is None:
              webdriver = webdriver_control.create()
          else:
              webdriver = state.webdriver
  
          nframes = len(plot)
          frames = []
          for i in range(nframes):
              plot.update(i)
              img = get_screenshot_as_png(plot.state, driver=webdriver)
              frames.append(img)
          if state.webdriver is not None:
              webdriver.close()
  
          bio = BytesIO()
          duration = (1.0 / self.fps) * 1000
          frames[0].save(
              bio,
              format="GIF",
              append_images=frames[1:],
              save_all=True,
              duration=duration,
              loop=0,
          )
          bio.seek(0)
          data = bio.read()
      elif fmt == "png":
          from bokeh.io.export import get_screenshot_as_png
  
          img = get_screenshot_as_png(
              plot.state, driver=state.webdriver
          )
          imgByteArr = BytesIO()
          img.save(imgByteArr, format="PNG")
          data = imgByteArr.getvalue()
      else:
          div = render_mimebundle(plot.state, doc, plot.comm)[0][
              "text/html"
          ]
  
      if as_script and fmt in ["png", "gif"]:
          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)
          div = tag.format(src=src, mime_type=mime_type, css="")
  
      plot.document = doc
      if as_script or data is None:
          return div
      else:
          return data
  
imports: import base64
  import logging
  from io import BytesIO
  import bokeh
  import param
  from bokeh.document import Document
  from bokeh.io import curdoc
  from bokeh.models import Model
  from bokeh.themes.theme import Theme
  from panel.io.notebook import render_mimebundle
  from panel.io.state import state
  from param.parameterized import bothmethod
  from ...core import HoloMap, Store
  from ..plot import Plot
  from ..renderer import HTML_TAGS, MIME_TYPES, Renderer
  from .util import compute_plot_size
label_desc: Use image node_id 3 for calling the BokehRenderer obj's underlying member method code with example usage: obj._figure_data(plot, fmt, doc, as_script) and returns: div, data