In [3]:
import altair.vegalite.v2 as vl
from altair.datasets import load_dataset

In [4]:
cars = load_dataset('cars')

In [5]:
cars.head()


Out[5]:
Acceleration Cylinders Displacement Horsepower Miles_per_Gallon Name Origin Weight_in_lbs Year
0 12.0 8 307.0 130.0 18.0 chevrolet chevelle malibu USA 3504 1970-01-01
1 11.5 8 350.0 165.0 15.0 buick skylark 320 USA 3693 1970-01-01
2 11.0 8 318.0 150.0 18.0 plymouth satellite USA 3436 1970-01-01
3 12.0 8 304.0 150.0 16.0 amc rebel sst USA 3433 1970-01-01
4 10.5 8 302.0 140.0 17.0 ford torino USA 3449 1970-01-01

In [6]:
vl.data_transformers.enable('json')

In [13]:
spec = {
    'data': vl.pipe(cars, vl.data_transformers.get()),
    'encoding': {
        'x': {'type': 'quantitative', 'field': 'Acceleration'},
        'y': {'type': 'quantitative', 'field': 'Displacement'},        
    },
    'mark': 'circle',
    'width': 400,
    'height': 300
}

In [14]:
vl.renderers.get()(spec)


Out[14]:
({'application/vnd.vegalite.v2+json': {'data': {'format': {'type': 'json'},
    'url': '/files/demo/altair-data-b86a7fce-ae41-4650-9b71-762db9f959de.json'},
   'encoding': {'x': {'field': 'Acceleration', 'type': 'quantitative'},
    'y': {'field': 'Displacement', 'type': 'quantitative'}},
   'height': 300,
   'mark': 'circle',
   'width': 400},
  'text/plain': '<VegaLite 2 object>'},
 {})

In [15]:
vl.vegalite(spec, validate=True)


<VegaLite 2 object>

In [16]:
vl.renderers.enable('json')

In [17]:
vl.vegalite(spec, validate=True)


<VegaLite 2 object>