Skip to content
Scattered Contour (Filled)

Scattered Contour (Filled)

Filled contour bands over scattered samples: tricontour()’s regions rather than its lines, Delaunay-triangulated the same way.

Scattered Contour (Filled)

Usage

from std.math import exp, sin

from dataviz import tricontourf
from dataviz import save

def main() raises:
    var x = List[Float64]()
    var y = List[Float64]()
    var z = List[Float64]()
    var seed = 12345
    for _ in range(240):
        seed = (seed * 1103515245 + 12345) % 2147483648
        var px = Float64(seed % 1200) / 100.0
        seed = (seed * 1103515245 + 12345) % 2147483648
        var py = Float64(seed % 800) / 100.0
        x.append(px)
        y.append(py)
        # Same illustrative well survey as tricontour(), rendered as
        # bands so concentration regions are easier to compare.
        var farm_x = (px - 3.2) / 1.6
        var farm_y = (py - 5.3) / 1.3
        var plant_x = (px - 9.0) / 1.2
        var plant_y = (py - 2.1) / 1.0
        var nitrate = 1.8 + 0.12 * px + 0.4 * sin(py * 1.7)
        nitrate += 5.8 * exp(-(farm_x * farm_x + farm_y * farm_y))
        nitrate += 3.6 * exp(-(plant_x * plant_x + plant_y * plant_y))
        z.append(nitrate)

    var c = tricontourf(
        x,
        y,
        z,
        level_count=10,
        title="Illustrative Groundwater Nitrate Bands (mg/L)",
        x_title="Easting (km)",
        y_title="Northing (km)",
    )
    save(c, "docs/src/examples/out_tricontourf.svg")

See Data shapes for shared input conventions.

Args:

  • x: Sample x coordinates.
  • y: Sample y coordinates, one per x entry.
  • z: The value at each sample.
  • levels: Explicit level values. Empty (the default) places level_count of them evenly inside the samples’ own range.
  • level_count: How many levels to place when levels is empty.
  • theme: Colors, sizes and spacing.
  • width: Canvas width in pixels.
  • height: Canvas height in pixels.
  • title: Chart title.
  • subtitle: Smaller line under the title.
  • x_title: X-axis label.
  • y_title: Y-axis label.

Related

Related charts: Scattered Contour · Triangular Mesh

Relevant API: tricontourf