Chart families, facets, and layout
XY presents charts as one shared figure model. A chart combines marks with axes and chart chrome, then turns that composition into a figure that can be shown live or exported. The model supports common Cartesian charts, a small set of polar and flow charts, and repeated panel layouts without changing the basic relationship between data, marks, and the figure. See the Python chart API and figure model for the general chart lifecycle.
Shared figure model
The figure is the common space in which every chart family is described. A mark expresses visible data or geometry, while axes, legends, tooltips, annotations, and interaction settings give that geometry meaning. Specialized chart helpers mainly prepare a useful composition of the same parts.
flowchart LR
A[Chart helper or neutral chart] --> B[Marks]
A --> C[Axes and chart chrome]
B --> D[Shared figure]
C --> D
D --> E[Live view]
D --> F[Static export]
D --> G[Facet panel]
Mark and chart composition
The neutral xy.chart(...) entry point allows different mark families to share one pair of axes. Named helpers such as xy.line_chart(...) and xy.heatmap_chart(...) provide clearer intent, but the important boundary is the mark composition inside the resulting figure. This makes overlays such as a line with points or a heatmap with contour lines part of the same chart rather than separate chart systems.
The shared figure also gives marks common axis binding, color and size channels, legends, tooltips, annotations, and view behavior. Data preparation and payload rules are described in Data ingestion and payloads; style rules are in Styling, themes, and annotations; view behavior is in Interaction and view state. This page focuses on the visual families that consume that shared model.
References: python/…/components.py• L3638-3827 python/…/components.py• L3962-4004 python/…/_figure.py• L112-185
Chart family entry points
Chart helpers group a primary mark or composition with the expected chart framing. The core Cartesian families are:
| Family | Main entry points | Visual purpose |
|---|---|---|
| Trend and relation | line_chart, area_chart, scatter_chart, step_chart, stairs_chart, stem_chart | Show change, paths, samples, or discrete transitions. |
| Comparison | bar_chart, column_chart | Compare categorical or numeric values with grouped, stacked, or normalized bars. |
| Distribution | histogram_chart, box_chart, violin_chart, ecdf_chart | Show counts, summaries, smoothed distributions, or cumulative share. |
| Two-dimensional field | heatmap_chart, contour_chart, hexbin_chart | Show a value field, isolines, or dense point concentration. |
| Intervals and geometry | errorbar_chart, error_band_chart, segments_chart, triangle_mesh_chart | Show uncertainty, independent spans, or explicit triangular regions. |
These helpers do not prevent mixed compositions. For example, a neutral chart can combine a scatter mark with an error band, while a bar chart can contain more than one bar series. The chart family names communicate the intended starting point; the marks define what the figure displays.
References: python/…/components.py• L6506-6519 python/…/components.py• L7018-7095 python/…/__init__.py• L57-138
Cartesian mark families
Cartesian marks use separable horizontal and vertical axes. They cover the main analytical needs: paths and points for relationships, rectangles for comparisons and bins, summaries for distributions, and bounded geometry for fields and intervals.
Trend and comparison marks
line and area marks express an ordered relationship between two channels. A line shows the path itself. An area fills the space between a value and a baseline. step and stairs keep the same path model while making changes occur at discrete edges. stem adds a baseline-to-value segment with an optional point marker.
bar and column marks express value by rectangle height or width. They support vertical and horizontal orientation plus grouped, stacked, and normalized arrangements. This family is suited to comparisons where category position and value length carry the main message.
References: python/…/marks.py• L1598-1762 python/…/marks.py• L1960-2177 python/…/marks.py• L3468-3578
Point, interval, and distribution marks
scatter shows individual observations. Its color and size may represent per-point values, so it can serve both relation plots and encoded point plots. errorbar adds uncertainty spans around observations. error_band shows a continuous interval around an ordered series. Large scatter views can change representation under the level-of-detail rules described in Level of detail, density, and streaming.
histogram groups one-dimensional values into bins. box summarizes groups with quartiles, whiskers, medians, and optional outliers. violin shows a bounded smoothed distribution for each group. ecdf shows cumulative share. These marks turn raw observations into compact views while keeping their distinct meanings.
References: python/…/marks.py• L1765-1799 python/…/marks.py• L1861-1930 python/…/marks.py• L2183-2387 python/…/marks.py• L2393-2570 python/…/marks.py• L2573-2832
Field and shape marks
heatmap maps a two-dimensional value matrix to rectangular cells. contour draws isolines from a regular grid and can add filled bands. hexbin groups dense point data into hexagonal cells. These marks describe a field or concentration rather than a separate visible object for every source row.
segments draws independent line spans. ribbon draws a band between two spans and is used for flow paths. triangle_mesh draws explicit triangular regions. They provide the geometric building blocks for interval, mesh, and flow views without changing the figure model.
References: python/…/marks.py• L374-459 python/…/marks.py• L2835-3007 python/…/marks.py• L3180-3429 python/…/marks.py• L3581-3619
Specialized coordinate and semantic families
Some views need more than Cartesian axes. XY keeps these views in the same figure model, but gives each one a clear contract for how marks, axes, and values should be read. Polar charts reinterpret the two main channels. Sankey and funnel charts use layout rules that give their shapes business meaning.
Polar coordinate charts
polar_chart maps the first mark channel to angle and the second to radius. theta_axis describes angular units, zero direction, travel direction, and visible sector. r_axis describes radial range, origin, and optional hole. A polar figure therefore uses the same mark language as a Cartesian figure while changing the meaning of the two axes.
The supported polar mark set is limited to line, scatter, area, bar, column, heatmap, contour, and errorbar. Unsupported marks are refused instead of being drawn with a Cartesian shape that could look valid but have the wrong geometry. Polar traces use direct drawing, so large polar inputs must be reduced or binned before charting. Zoom is off by default for most polar compositions because the center is fixed; a wind rose is the exception.
References: python/…/components.py• L6521-6566 python/…/_figure.py• L887-1034 python/…/config.py• L48-61
Radar and radial bar compositions
radar_chart is a polar composition for comparing several values across named spokes. It accepts area or line children, derives evenly spaced angles, and closes each series across the circular seam. fill=False changes area children into outlines without changing the data meaning.
polar_bar_chart uses bar marks as annular sectors. The bar width is angular, and base sets the inner radius. pie_chart is a higher-level radial bar composition: each positive value becomes a slice whose angular span represents its share. A nonzero hole makes it a donut.
References: python/…/components.py• L6569-6707 python/…/components.py• L6710-6861
Wind rose composition
wind_rose shows directional frequency split into speed bands. It bins compass bearings into angular sectors and stacks one polar bar series for each speed band. Bearings use degrees with north at zero and clockwise travel so the view follows the usual compass reading.
The radius represents frequency. This gives the wind rose a different layout meaning from a pie or radar chart and explains why it enables zoom by default. The chart owns a direction-and-count readout while the stacked bands retain their speed labels.
References: python/…/components.py• L6864-7015 tests/test_polar_charts.py• L358-416
Sankey flow diagrams
sankey_chart represents directed quantities between named nodes. Links keep their width from source to target, and nodes occupy layers derived from the flow graph. The layout places related nodes and stacks outgoing links so the band widths preserve the flow values.
The diagram uses the ribbon concept for both links and nodes. A link can transition from the source node color to the target node color, while a node is a ribbon with equal spans. Link rows and node rows keep semantic names and values for hover and selection rather than exposing placement coordinates as if they were data.
Sankey input must describe a valid directed graph. Empty input, self-links, duplicate links, negative values, and cycles are rejected because each would make the flow layout ambiguous or misleading.
References: python/…/components.py• L7098-7135 python/…/marks.py• L430-697 python/…/_sankey.py• L1-220
Funnel stage diagrams
funnel_chart represents an ordered process such as a conversion path. Each stage has a name and value. The stage axis keeps the declared order, while the cross axis centers the stage shape around zero and is used only for layout.
The chart supports both decreasing and increasing stage values. It reports each stage's overall share and its change from the prior stage, so it also represents re-entry or net growth instead of assuming that every process must narrow.
The default area geometry tapers toward the next stage to form a familiar funnel silhouette. Its painted area is a visual cue rather than a value measure. geometry="bar" keeps each stage at its own width when exact visual width matters. neck="taper" can bring the last area stage to a point, and min_width keeps small stages visible without changing their semantic values. Labels and tooltips can show stage value, share, conversion, and drop-off.
Undefined ratios, such as the first stage or a ratio with a zero denominator, remain undefined in the figure data and display as an em dash. The chart does not send an infinite ratio when numeric values have a range that would overflow the ratio.
Vertical funnels place the first stage at the top. Horizontal funnels place it at the left. A single chart cannot mix the two orientations because its axis framing would no longer have one clear meaning.
References: python/…/components.py• L7138-7261 python/…/marks.py• L700-1061 python/…/_funnel.py• L124-323 python/…/_funnel.py• L341-512 tests/test_funnel.py• L42-204 tests/test_funnel.py• L223-260 tests/test_funnel.py• L394-402 tests/test_funnel.py• L996-1008
Scatter-matrix coverage
Scatter-matrix or pair-plot layout is not part of the current core chart API. The roadmap marks it as planned, so engineers should build a matrix from explicit charts or facets rather than rely on an undocumented scatter_matrix entry point. The intended direction is to reuse scatter behavior across many coordinated panels.
References: spec/…/chart-roadmap.md• L137-139 spec/…/chart-roadmap.md• L168-171
Faceted panel layouts
Faceting repeats one chart composition for each value of a grouping field. facet_chart creates a small-multiple view: each panel has its own figure, while the facet wrapper controls panel order, grid placement, and optional coordination between panels.
Facet panels and domains
by can name a column in chart data or provide one value per row. Panels follow first-seen facet order, and each panel receives the rows for one facet value. The default shares the x and y domains so equal positions have equal meaning across panels.
Shared domains include the union of categorical values. This keeps a category at the same position even when it is absent from one panel. If an axis is categorical in some panels and numeric in others, that axis cannot be shared safely.
References: python/…/components.py• L5364-5457 python/…/components.py• L5458-5520 python/…/facets.py• L24-118
Facet grid geometry
cols sets the maximum number of panels in one row. The grid width is the total width, while the height is the height of each panel. The number of rows grows with the facet count, and gap sets the space between panels. Each panel uses the same chart composition and receives the facet label as its panel title.
The grid remains a chart-level object for display and export. It can show as one standalone document, as panel widgets in a notebook, or as a composed static image. The Export and static rendering page describes the output paths. This keeps layout concerns outside each panel without creating a second mark model.
References: python/…/components.py• L5421-5455 python/…/facets.py• L121-227 python/…/facets.py• L229-271
Facet interaction links
Panels are independent by default after their initial domains are shared. link="x", link="y", or link="both" synchronizes view changes on the chosen axes. link_select=True can also echo data-space selections across panels.
Linking forces the linked dimensions to start with a common domain. This prevents the first pan or zoom from moving panels from unlike starting views. Use shared domains when comparisons need a fixed frame; use links when panels must respond to the same later view or selection.
References: python/…/components.py• L5460-5532 python/…/components.py• L7269-7306
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the public chart helper, its primary mark kind, and the figure builder aligned. A new helper that does not reach the matching mark contract can produce a valid-looking but empty or wrong figure.
- Update the polar allowlist and its validation rules together when a mark gains polar support. The angle/radius mapping and the static and live render paths must agree.
- Preserve semantic tooltip rows when changing Sankey or funnel geometry. Placement columns must not replace source, target, stage, or value fields in user-facing events.
- Keep funnel visual width separate from semantic stage values. Changes to taper, minimum width, or stage geometry must not change conversion, share, drop-off, or tooltip data.
- Keep facet domain sharing and categorical union ordering aligned. A shared numeric range with different category positions makes panels compare unlike values.
- Keep facet grid size rules aligned across notebook display, HTML, SVG, and raster export. The total grid width and per-panel height are shared layout contracts.
- Treat scatter-matrix support as planned until a public composition and its panel coordination rules exist. Do not document a private or ad hoc matrix as a supported chart family.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| An unsupported mark is added to a polar chart | The mark could use Cartesian geometry inside a polar frame and show a plausible wrong picture | Polar build validation rejects mark kinds outside the supported set |
| A polar trace exceeds the direct point ceiling | The chart has no polar decimation or density path and may consume too much draw work | Reduce or bin the data before charting |
| A Sankey graph contains a cycle | Layer order and flow direction are not well-defined | The Sankey layout rejects cycles by node name |
| Funnel stages contain negative, missing, or non-finite values | Stage meaning and ratio output become invalid | Funnel stage validation rejects the offending stage |
| A funnel ratio has a zero denominator or overflows | The ratio has no useful numeric meaning and must not become an infinite wire value | Keep the ratio undefined and show the em dash |
| Funnel area geometry is used to compare exact values by painted area | The taper silhouette can suggest a value difference that the filled area does not measure | Use geometry="bar" when stage width must carry the exact value |
| A facet axis is categorical in one panel and numeric in another | Shared positions or domains cannot represent the same scale | Facet construction skips sharing for that axis and warns |
| A facet mixes vertical and horizontal funnel marks | The chart would need conflicting axis framing | Funnel chart construction rejects mixed orientations |
Key files
| File | Why to read it |
|---|---|
| python/…/components.py | Defines chart helpers, the shared Chart composition, polar compositions, flow charts, funnel charts, and facet setup. |
| python/…/_figure.py | Defines the shared figure state, axes, coordinate choice, trace model, and cross-family validation boundary. |
| python/…/marks.py | Defines the Cartesian mark families plus ribbon, Sankey, and funnel mark behavior. |
| python/…/config.py | States which mark kinds are supported in polar coordinates and the polar direct-draw limit. |
| python/…/facets.py | Defines the panel grid and the display and export layout for faceted figures. |
| python/…/_sankey.py | Defines the high-level node and link layout rules for flow diagrams. |
| python/…/_funnel.py | Defines funnel stage arithmetic, geometry choices, and label placement rules. |
| spec/…/chart-roadmap.md | Shows the supported chart breadth and records planned work such as scatter-matrix composition. |
| tests/test_plot_families.py | Summarizes the expected behavior of core mark families and their shared figure use. |
| tests/test_polar_charts.py | Covers polar compositions, supported marks, and cross-renderer polar behavior. |
| tests/test_sankey.py | Covers Sankey layout semantics and ribbon-based flow geometry. |
| tests/test_funnel.py | Covers funnel stage meaning, geometry, labels, semantic ratios, and chart composition. |
| tests/test_facets.py | Covers facet splitting, shared domains, links, and grid output. |