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

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

In [3]:
cars.head()


Out[3]:
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 [4]:
vl.data_transformers.enable('json')

In [5]:
spec = {
  "data": vl.pipe(cars, vl.data_transformers.get()),
  "vconcat": [{
    "selection": {
      "brush": {"type": "interval"}
    },
    "mark": "point",
    "encoding": {
      "x": {"field": "Horsepower","type": "quantitative"},
      "y": {"field": "Miles_per_Gallon","type": "quantitative"}
    }
  }, {
    "transform": [
      {"filter": {"selection": "brush"}}
    ],
    "mark": "point",
    "encoding": {
      "x": {
        "field": "Acceleration", "type": "quantitative",
        "scale": {"domain": [0,25]}
      },
      "y": {
        "field": "Displacement","type": "quantitative",
        "scale": {"domain": [0, 500]}
      }
    }
  }]
}

To render in the classic notebook run this line:


In [3]:
vg.renderers.enable('notebook')

To render in JupyterLab and nteract, run this


In [ ]:
vg.renderers.enable('default')

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


Out[12]:
({'application/vnd.vegalite.v2+json': {'data': {'format': {'type': 'json'},
    'url': '/files/github/altair-viz/altair/notebooks/altair-data-0004ed27-fa48-4358-8bac-bea454ea1c74.json'},
   'vconcat': [{'encoding': {'x': {'field': 'Horsepower',
       'type': 'quantitative'},
      'y': {'field': 'Miles_per_Gallon', 'type': 'quantitative'}},
     'mark': 'point',
     'selection': {'brush': {'type': 'interval'}}},
    {'encoding': {'x': {'field': 'Acceleration',
       'scale': {'domain': [0, 25]},
       'type': 'quantitative'},
      'y': {'field': 'Displacement',
       'scale': {'domain': [0, 500]},
       'type': 'quantitative'}},
     'mark': 'point',
     'transform': [{'filter': {'selection': 'brush'}}]}]},
  'text/plain': '<VegaLite 2 object>'},
 {})

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


<VegaLite 2 object>

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

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


<VegaLite 2 object>