2025, Dec 18 01:00

One color, many lines in Altair: plot grouped series with the detail channel and hide the legend

Learn how to plot grouped series in Altair with the detail channel: draw many lines in one color, remove legends, labels, and keep plots clear with replicates.

One color, many lines in Altair: how to draw grouped series without labels

When you plot multiple series in Altair, the canonical example uses the color channel to separate groups. That’s great for comparisons, but not ideal when you want many overlapping lines to share a single style, for example, simulation replicates of the same model where the legend and color palette add noise rather than value.

Here is the typical setup that assigns a different color per group:

import altair as al
from vega_datasets import data as vds
df_input = vds.stocks()
al.Chart(df_input).mark_line().encode(
    x='date:T',
    y='price:Q',
    color='symbol:N',
)

This produces separate colors for each line and includes labels in the legend.

What’s really happening

The color channel encodes the grouping key into a visual distinction, so each category gets its own hue and the chart generates a legend. If the goal is to plot many series as a single visual cohort while still treating them as distinct lines, color is the wrong channel for the job.

The right approach: use the detail channel

To draw multiple lines with the same color and ignore their labels, switch from color to detail. The detail channel tells Altair to group the data into separate marks without mapping that grouping to an aesthetic like color. As a result, you get multiple lines, one style, and no legend.

import altair as al
from vega_datasets import data as vds
df_input = vds.stocks()
al.Chart(df_input).mark_line().encode(
    x='date:T',
    y='price:Q',
    detail='symbol:N',
)

This renders all lines in the same color while still drawing one line per group.

Why this matters

When you have many groups—think dozens or hundreds of replicates—color quickly becomes a liability. It overwhelms the reader and forces the chart to juggle an unwieldy legend. Grouping via detail keeps the focus on the overall distribution and dynamics across replicates without introducing unnecessary visual distinctions.

Takeaways

If you need multiple series from the same dataset and don’t want them differentiated by color or labeled, put the grouping field on detail rather than color. You’ll get one line per group, all rendered uniformly, which scales cleanly when the number of groups grows and avoids clutter from legends and palettes.