class_docstr: This object is constructed from graphviz DOT content and knows how to render and save as SVG.
docstr: Save the svg of this tree visualization into filename argument.
  Can only save .svg; others fail with errors.
  See https://github.com/parrt/dtreeviz/issues/4
docstr_tok: ["Save","the","svg","of","this","tree","visualization","into","filename","argument",".","Can","only","save",".svg",";","others","fail","with","errors",".","See","https",":","\/\/github.com\/parrt\/dtreeviz\/issues\/4"]
code: def save(self, filename):
      """
      Save the svg of this tree visualization into filename argument.
      Can only save .svg; others fail with errors.
      See https://github.com/parrt/dtreeviz/issues/4
      """
      path = Path(filename)
      if not path.parent.exists:
          os.makedirs(path.parent)
  
      g = graphviz.Source(self.dot, format="svg")
      dotfilename = g.save(
          directory=path.parent.as_posix(), filename=path.stem
      )
      format = path.suffix[1:]  # ".svg" -> "svg" etc...
  
      if not filename.endswith(".svg"):
          # Mac I think could do any format if we required:
          #   brew reinstall pango librsvg cairo
          raise (
              Exception(
                  f"{PLATFORM} can only save .svg files: {filename}"
              )
          )
  
      # Gen .svg file from .dot but output .svg has image refs to other files
      cmd = ["dot", f"-T{format}", "-o", filename, dotfilename]
      # print(' '.join(cmd))
      if graphviz.__version__ <= "0.17":
          graphviz.backend.run(
              cmd, capture_output=True, check=True, quiet=False
          )
      else:
          graphviz.backend.execute.run_check(
              cmd, capture_output=True, check=True, quiet=False
          )
  
      if filename.endswith(".svg"):
          # now merge in referenced SVG images to make all-in-one file
          with open(filename, encoding="UTF-8") as f:
              svg = f.read()
          svg = inline_svg_images(svg)
          svg = scale_SVG(svg, self.scale)
          with open(filename, "w", encoding="UTF-8") as f:
              f.write(svg)
  
imports: import os
  import re
  import tempfile
  import warnings
  import xml.etree.cElementTree
  from pathlib import Path
  from sys import platform
  import graphviz
  import numpy
  import pandas
  from matplotlib import patches
  from numpy import ndarray
  from numbers import Number
  from typing import Tuple, Sequence
label_desc: Use image node_id 7 for calling the DTreeVizRender obj's underlying member method code with example usage: obj.save(filename) without return types