class_docstr: An object that collects relevant information about viewing Python code
  with visual annotations.
class_docstr_tok: ["An","object","that","collects","relevant","information","about","viewing","Python","code","with","visual","annotations","."]
docstr: Save viz in format according to file extension.
code: def savefig(self, filename):
      "Save viz in format according to file extension."
      if plt.fignum_exists(self.fignumber):
          # If the matplotlib figure is still active, save it
          self.filename = (
              filename  # Remember the file so we can pull it back
          )
          plt.savefig(
              filename, dpi=self.dpi, bbox_inches="tight", pad_inches=0
          )
      else:  # we have already closed it so try to copy to new filename from the previous
          if filename != self.filename:
              f, ext = os.path.splitext(filename)
              prev_f, prev_ext = os.path.splitext(self.filename)
              if ext != prev_ext:
                  print(
                      f"File extension {ext} differs from previous {prev_ext}; uses previous."
                  )
                  ext = prev_ext
              filename = (
                  f + ext
              )  # make sure that we don't copy raw bits and change the file extension to be inconsistent
              with open(self.filename, "rb") as f:
                  img = f.read()
              with open(filename, "wb") as f:
                  f.write(img)
              self.filename = filename
  
imports: import sys
  import os
  from pathlib import Path
  import tempfile
  import graphviz
  import graphviz.backend
  import token
  import matplotlib.patches
  import matplotlib.pyplot
  import matplotlib.colors
  from IPython.display import display, SVG
  from IPython import get_ipython
  import numpy
  import tsensor
  import tsensor.ast
  import tsensor.analysis
  import tsensor.parsing
label_desc: Use image node_id 6 for calling the PyVizView obj's underlying member method code with example usage: obj.savefig(filename) without return types