Skip to content

Flights Density

Density heatmap and contour lines for 200,000+ flights by departure hour and arrival delay. The sliders adjust the smoothing (bandwidth) and number of contour thresholds.

Loading Example...

Specification

js
import * as vg from "@uwdata/vgplot";

await vg.coordinator().exec([
  vg.loadParquet("flights", "data/flights-200k.parquet")
]);

const $bandwidth = vg.Param.value(7);
const $thresholds = vg.Param.value(10);

export default vg.vconcat(
  vg.hconcat(
    vg.slider({label: "Bandwidth (σ)", as: $bandwidth, min: 1, max: 100}),
    vg.slider({label: "Thresholds", as: $thresholds, min: 2, max: 20})
  ),
  vg.plot(
    vg.heatmap(
      vg.from("flights"),
      {x: "time", y: "delay", fill: "density", bandwidth: $bandwidth}
    ),
    vg.contour(
      vg.from("flights"),
      {
        x: "time",
        y: "delay",
        stroke: "white",
        strokeOpacity: 0.5,
        bandwidth: $bandwidth,
        thresholds: $thresholds
      }
    ),
    vg.colorScale("symlog"),
    vg.colorScheme("ylgnbu"),
    vg.xAxis("top"),
    vg.xLabelAnchor("center"),
    vg.xZero(true),
    vg.yAxis("right"),
    vg.yLabelAnchor("center"),
    vg.marginTop(30),
    vg.marginLeft(5),
    vg.marginRight(40),
    vg.width(700),
    vg.height(500)
  )
);
yaml
meta:
  title: Flights Density
  description: >
    Density `heatmap` and `contour` lines for 200,000+ flights by departure hour and arrival delay.
    The sliders adjust the smoothing (bandwidth) and number of contour thresholds.
data:
  flights: { file: data/flights-200k.parquet }
params:
  bandwidth: 7
  thresholds: 10
vconcat:
- hconcat:
  - input: slider
    label: Bandwidth (σ)
    as: $bandwidth
    min: 1
    max: 100
  - input: slider
    label: Thresholds
    as: $thresholds
    min: 2
    max: 20
- plot:
  - mark: heatmap
    data: { from: flights }
    x: time
    y: delay
    fill: density
    bandwidth: $bandwidth
  - mark: contour
    data: { from: flights }
    x: time
    y: delay
    stroke: white
    strokeOpacity: 0.5
    bandwidth: $bandwidth
    thresholds: $thresholds
  colorScale: symlog
  colorScheme: ylgnbu
  xAxis: top
  xLabelAnchor: center
  xZero: true
  yAxis: right
  yLabelAnchor: center
  marginTop: 30
  marginLeft: 5
  marginRight: 40
  width: 700
  height: 500
json
{
  "meta": {
    "title": "Flights Density",
    "description": "Density `heatmap` and `contour` lines for 200,000+ flights by departure hour and arrival delay. The sliders adjust the smoothing (bandwidth) and number of contour thresholds.\n"
  },
  "data": {
    "flights": {
      "file": "data/flights-200k.parquet"
    }
  },
  "params": {
    "bandwidth": 7,
    "thresholds": 10
  },
  "vconcat": [
    {
      "hconcat": [
        {
          "input": "slider",
          "label": "Bandwidth (σ)",
          "as": "$bandwidth",
          "min": 1,
          "max": 100
        },
        {
          "input": "slider",
          "label": "Thresholds",
          "as": "$thresholds",
          "min": 2,
          "max": 20
        }
      ]
    },
    {
      "plot": [
        {
          "mark": "heatmap",
          "data": {
            "from": "flights"
          },
          "x": "time",
          "y": "delay",
          "fill": "density",
          "bandwidth": "$bandwidth"
        },
        {
          "mark": "contour",
          "data": {
            "from": "flights"
          },
          "x": "time",
          "y": "delay",
          "stroke": "white",
          "strokeOpacity": 0.5,
          "bandwidth": "$bandwidth",
          "thresholds": "$thresholds"
        }
      ],
      "colorScale": "symlog",
      "colorScheme": "ylgnbu",
      "xAxis": "top",
      "xLabelAnchor": "center",
      "xZero": true,
      "yAxis": "right",
      "yLabelAnchor": "center",
      "marginTop": 30,
      "marginLeft": 5,
      "marginRight": 40,
      "width": 700,
      "height": 500
    }
  ]
}