code: def _figure_data(self, plot, fmt, as_script=False, **kwargs):
      if fmt == "gif":
          import plotly.io as pio
          from PIL import Image
          from plotly.io.orca import (
              ensure_server,
              shutdown_server,
              status,
          )
  
          running = status.state == "running"
          if not running:
              ensure_server()
  
          nframes = len(plot)
          frames = []
          for i in range(nframes):
              plot.update(i)
              img_bytes = BytesIO()
              figure = go.Figure(self.get_plot_state(plot))
              img = pio.to_image(figure, "png", validate=False)
              img_bytes.write(img)
              frames.append(Image.open(img_bytes))
  
          if not running:
              shutdown_server()
  
          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 in ("png", "svg"):
          import plotly.io as pio
  
          # Wrapping plot.state in go.Figure here performs validation
          # and applies any default theme.
          figure = go.Figure(self.get_plot_state(plot))
          data = pio.to_image(figure, fmt)
  
          if fmt == "svg":
              data = data.decode("utf-8")
      else:
          raise ValueError(f"Unsupported format: {fmt}")
  
      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)
          div = tag.format(src=src, mime_type=mime_type, css="")
          return div
      return data
  
file_path: holoviews/holoviews/plotting/plotly/renderer.py
imports: import base64
  from io import BytesIO
  import panel
  import param
  from param.parameterized import bothmethod
  from ...core import HoloMap
  from ...core.options import Store
  from ..renderer import HTML_TAGS, MIME_TYPES, Renderer
  from .callbacks import callbacks
  from .util import clean_internal_figure_properties
label_desc: Use image node_id 2 for calling the PlotlyRenderer obj's underlying member method code with example usage: obj._figure_data(plot, fmt, as_script) and returns: data, div