Contour Transform

Note: As of Vega ≥ 5.8 this transform is deprecated and may be removed in a future major release. For similar but more flexible functionality, please use the isocontour and kde2d transforms.

The contour transform models a spatial distribution of data values using a set of discrete levels. Each contour line is an isoline of constant value. A common use case is to convey density estimates for 2D point data, as these can provide a more scalable representation for large numbers of data points.

The contour transform generates a new stream of GeoJSON geometry data as output. These shapes can then be visualized using either the geoshape or geopath transform. This transform provides the functionality of both the contours and densityContour methods of the d3-contour module.

Transform Parameters

Property Type Description
size Number[ ] Required. The dimensions [width, height] over which to compute contours. If the values parameter is provided, this must be the dimensions of the input data. If density estimation is performed, this is the output view dimensions in pixels.
values Number[ ] An array of numeric values representing an width x height grid of values over which to compute contours. If unspecified, this transform will instead compute contours for the kernel density estimate of input data.
x Field The pixel x-coordinate field for density estimation.
y Field The pixel y-coordinate field for density estimation.
weight Field The data point weight field for density estimation. If unspecified, all data points are assumed to have a weight of 1. ≥ 4.0
cellSize Number Contour density calculation cell size.
bandwidth Number Kernel density estimation bandwidth.
smooth Boolean A boolean flag (default true) indicating if the contour polygons should be smoothed using linear interpolation. This parameter is ignored when using kernel density estimation.
thresholds Number[ ] A threshold array of explicit contour boundaries. If this parameter is set, the count and nice parameters will be ignored.
count Number The desired number of contours. This parameter is ignored if the thresholds parameter is provided.
nice Boolean A boolean flag (default false) indicating if the contour threshold values should be automatically aligned to “nice”, human-friendly values. Setting this flag may cause the number of thresholds to deviate from the exact count.


This example generates 10 levels of contours for the 2D kernel density estimate of a source data stream. The transform draws pre-computed pixel (x, y) coordinates from the x_value and y_value data fields, and uses the width and height signals to configure the area over which contours should be computed.

  "type": "contour",
  "x": "x_value",
  "y": "y_value",
  "size": [{"signal": "width"}, {"signal": "height"}],
  "count": 10