class_docstr: An immutable object representation of a visualization.
  
  Notes
  -----
  - A plot object is returned via the SFrame's or SArray's .plot() method
  
  Examples
  --------
  Suppose 'plt' is an Plot Object
  
  We can view it using:
  
  >>> plt.show()
  
  We can save it using:
  
  >>> plt.save('vega_spec.json')
  
  We can also save the vega representation of the plot without data:
  
  >>> plt.save('vega_spec.json', False)
class_docstr_tok: ["An","immutable","object","representation","of","a","visualization",".","Notes","--","--","-","-","A","plot","object","is","returned","via","the","SFrame","'s","or","SArray","'s",".plot","(",")","method","Examples","--","--","--","--","Suppose","'plt","'","is","an","Plot","Object","We","can","view","it","using",":",">",">",">","plt.show","(",")","We","can","save","it","using",":",">",">",">","plt.save","(","'vega_spec.json","'",")","We","can","also","save","the","vega","representation","of","the","plot","without","data",":",">",">",">","plt.save","(","'vega_spec.json","'",",","False",")"]
docstr: A method for saving the Plot object in a vega representation
  
  Parameters
  ----------
  filepath: string
      The destination filepath where the plot object must be saved as.
      The extension of this filepath determines what format the plot will
      be saved as. Currently supported formats are JSON, PNG, and SVG.
  
  Examples
  --------
  Suppose 'plt' is an Plot Object
  
  We can save it using:
  
  >>> plt.save('vega_spec.json')
  
  We can also save the vega representation of the plot without data:
  
  >>> plt.save('vega_spec.json', False)
  
  We can save the plot as a PNG/SVG using:
  
  >>> plt.save('test.png')
  >>> plt.save('test.svg')
docstr_tok: ["A","method","for","saving","the","Plot","object","in","a","vega","representation","Parameters","--","--","--","--","--","filepath",":","string","The","destination","filepath","where","the","plot","object","must","be","saved","as",".","The","extension","of","this","filepath","determines","what","format","the","plot","will","be","saved","as",".","Currently","supported","formats","are","JSON",",","PNG",",","and","SVG",".","Examples","--","--","--","--","Suppose","'plt","'","is","an","Plot","Object","We","can","save","it","using",":",">",">",">","plt.save","(","'vega_spec.json","'",")","We","can","also","save","the","vega","representation","of","the","plot","without","data",":",">",">",">","plt.save","(","'vega_spec.json","'",",","False",")","We","can","save","the","plot","as","a","PNG\/SVG","using",":",">",">",">","plt.save","(","'test.png","'",")",">",">",">","plt.save","(","'test.svg","'",")"]
code: def save(self, filepath):
      """
      A method for saving the Plot object in a vega representation
  
      Parameters
      ----------
      filepath: string
          The destination filepath where the plot object must be saved as.
          The extension of this filepath determines what format the plot will
          be saved as. Currently supported formats are JSON, PNG, and SVG.
  
      Examples
      --------
      Suppose 'plt' is an Plot Object
  
      We can save it using:
  
      >>> plt.save('vega_spec.json')
  
      We can also save the vega representation of the plot without data:
  
      >>> plt.save('vega_spec.json', False)
  
      We can save the plot as a PNG/SVG using:
  
      >>> plt.save('test.png')
      >>> plt.save('test.svg')
  
      """
      if type(filepath) != str:
          raise ValueError("filepath provided is not a string")
  
      if filepath.endswith(".json"):
          # save as vega json
          spec = self.get_vega(include_data=True)
          with open(filepath, "w") as fp:
              _json.dump(spec, fp)
      elif filepath.endswith(".png") or filepath.endswith(".svg"):
          # save as png/svg, but json first
          spec = self.get_vega(include_data=True)
          EXTENSION_START_INDEX = -3
          extension = filepath[EXTENSION_START_INDEX:]
          temp_file_tuple = _mkstemp()
          temp_file_path = temp_file_tuple[1]
          with open(temp_file_path, "w") as fp:
              _json.dump(spec, fp)
          dirname = _os.path.dirname(__file__)
          relative_path_to_vg2png_vg2svg = "../vg2" + extension
          absolute_path_to_vg2png_vg2svg = _os.path.join(
              dirname, relative_path_to_vg2png_vg2svg
          )
          # try node vg2[png|svg] json_filepath out_filepath
          (exitcode, stdout, stderr) = _run_cmdline(
              "node "
              + absolute_path_to_vg2png_vg2svg
              + " "
              + temp_file_path
              + " "
              + filepath
          )
  
          if exitcode == _NODE_NOT_FOUND_ERROR_CODE:
              # user doesn't have node installed
              raise RuntimeError(
                  "Node.js not found. Saving as PNG and SVG"
                  + " requires Node.js, please download and install Node.js "
                  + "from here and try again: https://nodejs.org/en/download/"
              )
          elif exitcode == _CANVAS_PREBUILT_NOT_FOUND_ERROR:
              # try to see if canvas-prebuilt is globally installed
              # if it is, then link it
              # if not, tell the user to install it
              (
                  is_installed_exitcode,
                  is_installed_stdout,
                  is_installed_stderr,
              ) = _run_cmdline("npm ls -g -json | grep canvas-prebuilt")
              if is_installed_exitcode == _SUCCESS:
                  # npm link canvas-prebuilt
                  (
                      link_exitcode,
                      link_stdout,
                      link_stderr,
                  ) = _run_cmdline("npm link canvas-prebuilt")
                  if link_exitcode == _PERMISSION_DENIED_ERROR_CODE:
                      # They don't have permission, tell them.
                      raise RuntimeError(
                          link_stderr
                          + "\n\n"
                          + "`npm link canvas-prebuilt` failed, "
                          + "Permission Denied."
                      )
                  elif link_exitcode == _SUCCESS:
                      # canvas-prebuilt link is now successful, so run the
                      # node vg2[png|svg] json_filepath out_filepath
                      # command again.
                      (exitcode, stdout, stderr) = _run_cmdline(
                          "node "
                          + absolute_path_to_vg2png_vg2svg
                          + " "
                          + temp_file_path
                          + " "
                          + filepath
                      )
                      if exitcode != _SUCCESS:
                          # something else that we have not identified yet
                          # happened.
                          raise RuntimeError(stderr)
                  else:
                      raise RuntimeError(link_stderr)
              else:
                  raise RuntimeError(
                      "canvas-prebuilt not found. "
                      + "Saving as PNG and SVG requires canvas-prebuilt, "
                      + "please download and install canvas-prebuilt by "
                      + "running this command, and try again: "
                      + "`npm install -g canvas-prebuilt`"
                  )
          elif exitcode == _SUCCESS:
              pass
          else:
              raise RuntimeError(stderr)
          # delete temp file that user didn't ask for
          _run_cmdline("rm " + temp_file_path)
      else:
          raise NotImplementedError(
              "filename must end in" + " .json, .svg, or .png"
          )
  
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import json
  import os
  import sys
  from tempfile import mkstemp
  from subprocess import Popen
  from subprocess import PIPE
label_desc: Use image node_id 3 for calling the Plot obj's underlying member method code with example usage: obj.save(filepath) without return types