For AI agents: the complete XY documentation index is at llms.txt. Markdown versions are available by appending .md or sending Accept: text/markdown.
Chart Gallery

/

Line Chart in Python

Line Charts in Python

A line chart (also called a line graph or line plot) connects ordered observations to show a trend over time or any continuous sequence. With xy you create an interactive line chart in Python that stays smooth at millions of points: pan, zoom, and hover work by default, and long lines are decimated to the visible resolution and refined as you zoom.

Jump to multiple series, smooth curves, or large and real-time data.

Create a Line Chart

Pass equal-length x and y arrays to line. This is the minimal Python line chart:

Start Building Now!

Interactive Line Charts

Every line chart is interactive out of the box — drag to pan, scroll or pinch to zoom, and hover to inspect exact values with a tooltip. No configuration is required; the same chart renders in a notebook, a Reflex app, or exported HTML.

Smooth vs. Straight Lines

Keep the default straight segments when each observation should stay explicit, or set curve="smooth" for interpolation. Use dash for plan/actual or forecast comparisons.

Start Building Now!

Plot Multiple Line Series

Layer several named line marks and add a legend() to compare series. Bind marks to named axes when series use different units. The example above overlays two series; add as many as you need.

Large and Real-Time Line Charts

xy is built for large data: a line with millions of points renders as a decimated path sized to the screen, then refines when the viewport changes, so navigation never blocks. For streaming updates, see real-time and streaming data, and for the performance model see large data and performance.

Start Building Now!

Line Chart Options

OptionPurpose
colorLine color (any CSS color).
widthStroke width in pixels.
opacityLine opacity from 0 to 1.
curve"linear" (default) or "smooth" for interpolation.
dashDash pattern, e.g. "dashed", for plan/actual comparisons.
nameSeries label shown in the legend().

Missing numeric values create gaps in the line. Pass column names with data= instead of arrays when your data is a table.

API Reference

xy.line_chart

A line chart composing `line` marks and axis/legend children.

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. Defaults to on for Cartesian charts and off for polar ones (`wind_rose` excepted);

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.

coordsstr

Coordinate system, ``"cartesian"`` (default) or ``"polar"``. Under ``"polar"`` each mark's first channel is the angle and its second is the radius. Prefer ``xy.polar_chart(...)``, which sets this for you.

FAQ

How do I make an interactive line chart in Python?

Call xy.line(x, y) inside xy.chart(...) and render it. Pan, zoom, and hover are enabled automatically — no callbacks or extra libraries required.

How many points can a line chart plot?

Millions. xy decimates a long line to the visible pixels and refines it on zoom, so a multi-million-point line stays interactive instead of freezing the page.

How do I plot multiple lines on one chart?

Add one named line mark per series inside the same xy.chart(...) and include xy.legend().

How do I draw a smooth line instead of straight segments?

Pass curve="smooth" to line. Omit it to keep straight segments between observations.

Built with Reflex