Basic Vega-Lite Example


In [7]:
import pandas as pd
df = pd.read_json('cars.json')

In [8]:
df[:10]


Out[8]:
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
1 11.5 8 350.0 165.0 15.0 buick skylark 320 USA 3693 1970
2 11.0 8 318.0 150.0 18.0 plymouth satellite USA 3436 1970
3 12.0 8 304.0 150.0 16.0 amc rebel sst USA 3433 1970
4 10.5 8 302.0 140.0 17.0 ford torino USA 3449 1970
5 10.0 8 429.0 198.0 15.0 ford galaxie 500 USA 4341 1970
6 9.0 8 454.0 220.0 14.0 chevrolet impala USA 4354 1970
7 8.5 8 440.0 215.0 14.0 plymouth fury iii USA 4312 1970
8 10.0 8 455.0 225.0 14.0 pontiac catalina USA 4425 1970
9 8.5 8 390.0 190.0 15.0 amc ambassador dpl USA 3850 1970

In [9]:
from vega import VegaLite

In [10]:
VegaLite({
  "mark": "point",
  "encoding": {
    "y": {"type": "quantitative","field": "Acceleration"},
    "x": {"type": "quantitative","field": "Horsepower"}
  }
}, df)



In [11]:
VegaLite({
  "description": "A scatterplot showing horsepower and miles per gallons.",
  "mark": "point",
  "encoding": {
    "x": {"field": "Horsepower", "type": "quantitative"},
    "y": {"field": "Miles_per_Gallon", "type": "quantitative"},
    "color": {"field": "Origin", "type": "nominal"},
    "shape": {"field": "Origin", "type": "nominal"}
  }
}, df)



In [ ]: