plotlet v0.6.2

contour

Gridded & matrix

Minimal call

import math
def z(x, y):
    return (math.exp(-(x + 1) ** 2 - y ** 2)
            + math.exp(-(x - 1) ** 2 - (y - 1) ** 2))
grid = [[z(-3 + 6 * i / 30, -3 + 6 * j / 30) for i in range(31)]
        for j in range(31)]

c = pt.chart(xlabel="x", ylabel="y")
c.add_contour(grid, extent=(-3, 3, -3, 3), cmap="viridis",
              levels=[0.1, 0.3, 0.5, 0.7, 0.9])

Docstring

Contour-line isolines on a 2-D scalar grid via marching squares.

Pre-computed grid input — the companion to `kde_2d` (which estimates a
grid from data). The classic 2-D analytic-function viewer — useful for
posterior surfaces, energy landscapes, and 2-D KDE visualisations.

API: c.add_contour(grid, levels=[...], extent=(x0, x1, y0, y1))

`grid` is a 2-D nested list with shape (nrows, ncols). `levels` defaults
to 5 evenly-spaced values between grid min/max.

Styling kwargs:
  levels=None        list of iso-density level values
  extent=None        (x0, x1, y0, y1) data-space bounds; defaults to grid index
  fill=False         True fills the level regions (mpl contourf) instead of
                     stroking iso-lines; lowest level painted first
  cmap=None          colormap name for colouring lines/fills by level
  color=None         single fallback colour when cmap is unset
  alpha=None         fill opacity (fill=True only); defaults to 1 with cmap,
                     0.25 for a single-color fill so levels stack visibly
  linewidth=1.2      contour stroke width