altair: Error saving to SVG

Hi. Using the first example in the docs

from altair import Chart, load_dataset

# load built-in dataset as a pandas DataFrame
cars = load_dataset('cars')

chart = Chart(cars).mark_circle().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
)

the following attempt to save to SVG fails

chart.savechart('cars.jpg','jpg')
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-14-b070806b7bcc>", line 1, in <module>
    chart.savechart('cars.jpg','jpg')
  File "/usr/local/lib/python2.7/site-packages/altair/api.py", line 182, in savechart
    supported = _node.SUPPORTED_FILETYPES + ['json', 'html']
NameError: global name '_node' is not defined

and attempting to use vl2svg directly gives the error

vl2svg cars.json cars.jpg
/usr/local/lib/node_modules/vega/build/vega.js:686
  throw Error(message);
  ^

Error: Missing required "filter" parameter: "expr"
    at error (/usr/local/lib/node_modules/vega/build/vega.js:686:9)
    at parseParameter$1 (/usr/local/lib/node_modules/vega/build/vega.js:28796:9)
    at parseParameters (/usr/local/lib/node_modules/vega/build/vega.js:28775:25)
    at parseTransform (/usr/local/lib/node_modules/vega/build/vega.js:28763:35)
    at /usr/local/lib/node_modules/vega/build/vega.js:29639:23
    at Array.forEach (native)
    at parseData$1 (/usr/local/lib/node_modules/vega/build/vega.js:29638:20)
    at /usr/local/lib/node_modules/vega/build/vega.js:30045:5
    at Array.forEach (native)
    at parseSpec (/usr/local/lib/node_modules/vega/build/vega.js:30044:22)

I have installed canvas, vega and vega-lite and altair is the pypi version.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

This is no longer relevant, because Altair 2 uses selenium rather than node for programmatic export.

For what it’s worth, I can no longer get this to work on any of my machines. I think the NodeJS+shell dependency is something we’re going to have to figure out how to move away from (Bokeh has an interesting approach that we may adopt)

The issue is that the vl2svg command is not available in the environment in which Python is running. You’ll have to make sure you’ve installed that tool, and adjust your system path so that the command works when executed from Python.

Sorry it’s not easier, but currently there’s no good way to automatically interface between Python and NodeJS. If you know of one, please let us know!