Components

/

Triangle Mesh in Python

Triangle Mesh Charts in Python

A triangle mesh (also called a triangle mesh chart or triangle mesh plot) renders a surface from explicit triangles, each defined by its three vertices. With xy you build a triangle mesh in Python when you already have irregular geometry or precomputed topology — the low-level choice where a grid-based surface won't fit. You give each triangle its vertices and an optional color value, and the mesh stays interactive with pan, zoom, and hover.

Jump to creating a triangle mesh, when to use one, or the options.

Create a Triangle Mesh

Give triangle_mesh the three vertices of each triangle — (x0, y0), (x1, y1), (x2, y2) — plus a per-triangle color value mapped through the colormap:

Color a Computed Mesh by Value

Meshes are usually generated, not hand-written — here a small grid is triangulated in a loop and each triangle's color is a function value at its centroid, mapped through colormap over an explicit domain with no stroke:

Layer Constant-Color and Value-Colored Meshes

color also accepts a single CSS color for a constant fill, and one chart can layer several meshes — this fan pairs a value-colored inner ring with a constant-fill outer ring whose edges are drawn via stroke and stroke_width:

When to Use a Triangle Mesh

triangle_mesh takes explicit x0/y0, x1/y1, x2/y2 vertices per triangle — the low-level choice when you already have irregular surfaces or precomputed topology and want full control over the geometry. When your surface comes from values on a regular grid, a heatmap or contour plot is usually the simpler fit.

Triangle Mesh Options

OptionPurpose
x0 / y0, x1 / y1, x2 / y2The three vertices of each triangle.
colorConstant fill, or a per-triangle channel mapped through colormap.
colormapNamed colormap for the color channel, e.g. "purples".
domainValue range mapped onto the colormap, e.g. (0, 1).
strokeEdge color drawn around each triangle.
stroke_widthEdge stroke width in pixels.
opacityTriangle fill opacity from 0 to 1.

Pass column names with data= instead of arrays when your vertices live in a table.

  • Contour plots — level curves from values on a grid.
  • Heatmaps — color a regular grid of values by magnitude.

API Reference

xy.triangle_mesh_chart

A filled triangular mesh chart.

Props

PropTypeDescription
*childrenComponent

Marks, axes, annotations, and chart chrome.

titleOptional[str]

Title shown above the plot.

widthint | str

Chart width in pixels or a CSS size such as ``"100%"``.

heightint | str

Chart height in pixels or a CSS size such as ``"100%"``.

paddingUnion[float, Sequence[float], None]

Plot margins, as one value or a sequence of side values. Use zero for an edge-to-edge sparkline.

dataTableLike

Chart-level data used by marks that omit their own ``data``.

class_nameOptional[str]

CSS class applied to the chart container.

class_namesOptional[dict[str, str]]

CSS classes keyed by stable chart DOM slot.

styleOptional[dict[str, StyleValue]]

Inline style overrides for the chart container.

stylesOptional[dict[str, dict[str, StyleValue]]]

Inline style mappings keyed by stable chart DOM slot.

on_hoverOptional[Callable[[dict], None]]

Callback receiving hover event payloads.

on_clickOptional[Callable[[dict], None]]

Callback receiving picked-mark click payloads.

on_brushOptional[Callable[[dict], None]]

Callback receiving brush event payloads.

on_selectOptional[Callable[[Selection], None]]

Callback receiving data-space selections.

on_view_changeOptional[Callable[[dict], None]]

Callback receiving viewport change payloads.

hoverOptional[bool]

Whether pointer movement emits hover events.

clickOptional[bool]

Whether picked marks emit click events.

selectOptional[bool]

Whether shift-drag box selection is enabled.

brushOptional[bool]

Whether brush selection is enabled.

crosshairOptional[bool]

Whether plot-aligned hover guides are shown.

navigationOptional[bool]

Whether browser pan and zoom navigation is enabled.

panOptional[bool]

Whether plain-drag panning is enabled.

pan_axesOptional[tuple[str, ...]]

Declared axis IDs translated by pan gestures.

zoomOptional[bool]

Whether viewport zoom is enabled.

default_drag_actionOptional[DefaultDragAction]

Initial action performed by a plain plot drag.

zoom_axesOptional[tuple[str, ...]]

Declared axis IDs changed by zoom gestures and controls.

zoom_limitsOptional[ZoomLimits]

Minimum and maximum magnification globally or by axis.

wheel_zoomOptional[bool]

Whether wheel and trackpad zoom is available.

box_zoomOptional[bool]

Whether box zoom is available as a drag action.

zoom_buttonsOptional[bool]

Whether modebar Zoom In/Out commands are available.

double_click_resetOptional[bool]

Whether double-click restores ``reset_axes``.

reset_axesOptional[tuple[str, ...]]

Declared axis IDs restored by reset.

link_groupOptional[str]

Identifier used to synchronize charts in the browser.

link_axesOptional[tuple[str, ...]]

Axes synchronized within the link group.

FAQ

How do I make a triangle mesh in Python?

Call xy.triangle_mesh(...) with the three vertices of each triangle inside xy.triangle_mesh_chart(...) and render it. Pan, zoom, and hover work on the triangle mesh graph automatically.

How do I color triangles by value?

Pass a per-triangle list to color, set a colormap, and give a domain for the value range. Each triangle's value is mapped through the colormap; pass a single CSS color instead for a constant fill.

When should I use a triangle mesh instead of a heatmap?

Use a triangle mesh for irregular surfaces or precomputed topology where you control each triangle's vertices. Use a heatmap or contour plot when your values sit on a regular grid.

How do I draw the edges of each triangle?

Set stroke for the edge color and stroke_width for its thickness, as the demo does with a purple outline.

Built with Reflex