Composition Model

Composition Model

An XY chart starts with one container and a set of small Python specifications. The container creates the plotting surface. Marks turn data into visible geometry, while axes, annotations, legends, tooltips, themes, and interaction policies describe how that surface should behave.

Shared values such as data, title, dimensions, and callbacks are container props. Methods such as show(), to_html(), and write_image() operate on the composed chart after it has been built.

Compose one chart

This interactive example combines bars, a line, an annotation, axes, a legend, a shared tooltip, and crosshair behavior in one panel:

The xy chart is independent of Reflex; reflex_xy.chart(...) is only the adapter used to mount this documentation preview.

Anatomy of the chart

API roleIn the exampleResponsibility
Containerxy.chart(...)Creates one panel and allows mixed mark families
Container propsdata=, title=Supply shared data and layout metadata
Marksbar(), line()Turn columns into geometry, in declaration order
Axesx_axis(), y_axis()Define scales, domains, ticks, labels, and formatting
Annotationvline()Places a data-aligned event marker
Presentationlegend(), tooltip()Adds a series key and hover readout
Behaviorinteraction_config()Configures hover, selection, and navigation policy
Chart methodsshow(), to_html(), write_image()Display or export the finished composition

Three composition rules

  1. Shared data flows down. A chart-level data= supplies every mark that uses named columns. A mark-level data= overrides it for that mark.
  2. Declaration order controls layering. Marks render in order, so the target line above is painted after the bars.
  3. Settings resolve by family. Singleton configuration nodes—such as legends, tooltips, colorbars, modebars, export settings, and animation settings—use the last node of their family. Themes and interaction_config() nodes merge in declaration order; later explicit values win only where they overlap.

Choose a container

The container communicates intent; it does not select a different rendering engine.

What you are buildingContainer
One primary mark familyline_chart(), scatter_chart(), bar_chart(), and peers
Different mark kinds in one panelNeutral chart()
One template repeated by groupfacet_chart()

Here every rendered observation is a point, so scatter_chart() is the clearest container:

Family containers such as scatter_chart() return the same Chart interface as neutral chart(). facet_chart() repeats a composition over groups and returns a FacetChart with grid-aware output methods.

Keep application state outside the chart

interaction_config() describes browser behavior; the host connects chart events to Python application state. Core callbacks are for a live notebook widget, while Reflex events are configured on reflex_xy.chart(...). A chart rendered without a Python event bridge still pans, zooms, and resolves tooltips locally.

See Interactions and Selections for the interaction model and Reflex integration for server callback examples.

Declarative structure, live data

Adding or removing marks means composing a new chart. Live APIs can append points to line and scatter traces, inspect rendered points, or select a range from scatter data; Reflex server-driven updates require a registered live chart. See Large Data and Performance for representation choices and Reflex integration for live updates.

For output, use show() or widget() in notebooks, to_html() for a standalone document, to_image() for bytes, and write_image() for a file.

Learn the core concepts

GoalContinue with
Bind arrays, tables, dates, and categoriesData and Columns
Control domains, scales, ticks, and named axesAxes and Scales
Add navigation, callbacks, and exact selectionInteractions and Selections
Scale from direct points to large-data representationsLarge Data and Performance
Set chart-local behavior and export defaultsConfiguration

For finished examples, browse the Gallery. For browser entrance and data-update motion, continue with Animations and data transitions.

Built with Reflex