class_docstr: Class Docstring
  
  - Styling (.style)
  - Plotting (.plot)
  - Callouts (.callout)
  - Axes (.axes)
  - Bokeh figure (.figure)
class_docstr_tok: ["Class","Docstring","-","Styling","(",".style",")","-","Plotting","(",".plot",")","-","Callouts","(",".callout",")","-","Axes","(",".axes",")","-","Bokeh","figure","(",".figure",")"]
docstr: Convert figure object to PNG
  Bokeh can only save figure objects as html.
  To convert to PNG the HTML file is opened in a headless browser.
docstr_tok: ["Convert","figure","object","to","PNG","Bokeh","can","only","save","figure","objects","as","html",".","To","convert","to","PNG","the","HTML","file","is","opened","in","a","headless","browser","."]
code: def _figure_to_png(self):
      """Convert figure object to PNG
      Bokeh can only save figure objects as html.
      To convert to PNG the HTML file is opened in a headless browser.
      """
      driver = self._initialize_webdriver()
      # Save figure as HTML
      html = file_html(self.figure, resources=INLINE, title="")
      fp = tempfile.NamedTemporaryFile(
          "w", prefix="chartify", suffix=".html", encoding="utf-8"
      )
      fp.write(html)
      fp.flush()
      # Open html file in the browser.
      driver.get("file:///" + fp.name)
      driver.execute_script("document.body.style.margin = '0px';")
      png = driver.get_screenshot_as_png()
      driver.quit()
      fp.close()
      # Resize image if necessary.
      image = Image.open(BytesIO(png))
      target_dimensions = (
          self.style.plot_width,
          self.style.plot_height,
      )
      if image.size != target_dimensions:
          image = image.resize(
              target_dimensions, resample=Resampling.LANCZOS
          )
      return image
  
imports: from collections import OrderedDict
  from functools import wraps
  import io
  from io import BytesIO
  import tempfile
  import warnings
  import bokeh
  from bokeh.io.export import _SVG_SCRIPT, wait_until_render_complete
  import bokeh.plotting
  from bokeh.embed import file_html
  from bokeh.resources import INLINE
  from IPython.display import display
  from PIL import Image
  from PIL.Image import Resampling
  from selenium import webdriver
  from selenium.webdriver.chrome.options import Options
  from chartify._core.style import Style
  from chartify._core.axes import BaseAxes, SecondYNumericalAxis, SecondAxis
  from chartify._core.plot import BasePlot
  from chartify._core.callout import Callout
  from chartify._core.options import options
label_desc: Use image node_id 19 for calling the Chart obj's underlying member method code with example usage: obj._figure_to_png() and returns: image