Volcano Contours Example

A colored contour plot of the Maungawhau volcano in New Zealand. This example demonstrates contour generation directly from a provided grid of data values, rather than performing kernel density estimation on a discrete point set.

Vega JSON Specification <>

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "description": "A contour plot of the Maungawhau volcano in New Zealand.",
  "width": 960,
  "autosize": "none",

  "signals": [
    {
      "name": "grid",
      "init": "data('volcano')[0]"
    },
    {
      "name": "height",
      "update": "round(grid.height * width / grid.width)"
    },
    {
      "name": "smooth", "value": true,
      "bind": {"input": "radio", "options": [true, false]}
    }
  ],

  "data": [
    {
      "name": "volcano",
      "url": "data/volcano.json"
    },
    {
      "name": "contours",
      "source": "volcano",
      "transform": [
        {
          "type": "isocontour",
          "scale": {"expr": "width / datum.width"},
          "smooth": {"signal": "smooth"},
          "thresholds": {"signal": "sequence(90, 195, 5)"}
        }
      ]
    }
  ],

  "scales": [
    {
      "name": "color",
      "type": "linear",
      "domain": [90, 190],
      "range": {"scheme": "blueorange"}
    }
  ],

  "marks": [
    {
      "type": "path",
      "from": {"data": "contours"},
      "encode": {
        "enter": {
          "stroke": {"value": "#ccc"},
          "strokeWidth": {"value": 1},
          "fill": {"scale": "color", "field": "contour.value"}
        }
      },
      "transform": [
        {
          "type": "geopath",
          "field": "datum.contour"
        }
      ]
    }
  ]
}