Skip to main content
v2026.11,858 entries · CC-BY 4.0

Seaborn Line Plots: sns.lineplot Syntax, Error Bands and Multiple Lines

How to draw seaborn line plots with sns.lineplot: multiple lines, what the default 95% bootstrapped band means, and one line per subject for repeated data.

Written and maintained by CASRAI Editorial Board

Last updated

Seaborn line plots are drawn with seaborn.lineplot(), which takes a DataFrame plus x and y column names and returns a matplotlib Axes. What sets it apart from a plain matplotlib line is what it does when your data has several measurements at the same x value: by default it plots the mean and a 95% bootstrapped confidence interval around it. This guide follows the seaborn 0.13.2 documentation and focuses on that behavior, on repeated-measures data (one line per subject), and on the errorbar argument that replaced the deprecated ci, which many older tutorials still use.

What seaborn line plots are used for in research

A line plot shows how a measured quantity changes along an ordered variable such as time, dose or year. In seaborn’s data model the call is sns.lineplot(data=..., x=..., y=...). When the data are in long form and an x value repeats, the repeated values are aggregated, so one call summarizes replicates (several samples, trials or runs per time point) without a separate groupby step. The semantic arguments hue (different colors), size (different widths) and style (dashes or markers, always treated as categorical) split the data into several lines. The figure-level equivalent is relplot() with kind='line', which can facet across a grid.

It sits in the same family as the other seaborn plot types covered in the seaborn violin plots and seaborn heatmap guides. If you are deciding between seaborn and plain matplotlib, see seaborn vs matplotlib.

Install or access

The seaborn installation page lists Python 3.8+ and these commands:

pip install seaborn
pip install seaborn[stats]
conda install seaborn
conda install seaborn -c conda-forge

The mandatory dependencies are numpy, pandas and matplotlib. The optional ones are statsmodels, scipy and fastcluster. The line plot itself needs only the mandatory set. Matplotlib is imported separately when you need to show or save the figure; see import matplotlib.pyplot as plt.

Step-by-step: draw a seaborn line plot

The examples below are the ones used in the official seaborn documentation, with the library’s built-in flights and fmri example datasets.

  1. Load the data and plot one line.
    import seaborn as sns
    import matplotlib.pyplot as plt
    flights = sns.load_dataset("flights")
    may_flights = flights.query("month == 'May'")
    sns.lineplot(data=may_flights, x="year", y="passengers")
    plt.show()
  2. Plot wide-form data. Pass a wide DataFrame to data and each column becomes its own line. A single Series is plotted against its index.
    flights_wide = flights.pivot(index="year", columns="month", values="passengers")
    sns.lineplot(data=flights_wide)
  3. Draw one line per group with hue. With long-form data, assign a column to hue.
    sns.lineplot(data=flights, x="year", y="passengers", hue="month")

    Colors can be changed with the palette argument; see seaborn color palettes.

  4. Add markers and dashes with style.
    fmri = sns.load_dataset("fmri")
    sns.lineplot(data=fmri, x="timepoint", y="signal", hue="event", style="event", markers=True, dashes=False)
  5. Change the uncertainty display. The fmri data has several observations per timepoint, so the default draws a mean line with a band. To draw bars at two standard errors instead:
    sns.lineplot(data=fmri, x="timepoint", y="signal", hue="event", err_style="bars", errorbar=("se", 2))
  6. Draw one line per subject. For repeated measures, set units to the subject column and turn aggregation off with estimator=None.
    sns.lineplot(data=fmri.query("event == 'stim'"), x="timepoint", y="signal", hue="region", units="subject", estimator=None)

    Lines drawn with units get no legend entry.

Arguments that seaborn does not define itself are passed on to matplotlib’s Axes.plot(), so standard line keywords can be added. For legends and titles on the returned Axes, see legend in matplotlib.

Output and how to read it

What the shaded band is

When several observations share an x value, the line is the mean and the band is, by default, a 95% confidence interval of that mean. The seaborn tutorial states that these intervals are computed using bootstrapping, which can be time-intensive for larger datasets. The signature defaults are estimator='mean', errorbar=('ci', 95), n_boot=1000 and err_style='band'. Set seed to make the bootstrap reproducible between runs.

Changing what the band means

The errorbar argument accepts "pi", "se", "sd", a (method, level) tuple, a callable, or None. A standard-deviation band describes spread in the observations, while a confidence interval describes uncertainty in the mean, so the two answer different questions. Because the default band is easy to mistake for spread, state in the figure caption which interval is drawn (for example “mean with 95% bootstrapped CI, 1000 resamples”).

Setting Effect
errorbar=("ci", 95) (default) Mean with a 95% bootstrapped confidence interval
errorbar="sd" Standard deviation of the observations
errorbar=("se", 2) Two standard errors
errorbar=None No uncertainty display, and no bootstrapping cost
estimator=None All observations drawn, no aggregation
err_style="bars" Error bars instead of a band

The tutorial warns that estimator=None might produce a strange effect when the data have multiple observations at each point, which is why it is normally paired with units.

Troubleshooting

The line zigzags back and forth

By default, seaborn sorts the data by the x values before plotting. If you need the line to follow the order of the rows, for example a trajectory where x is not monotonic, pass sort=False. If you set estimator=None without units and several rows share an x value, the line will also look odd, because every observation is drawn; add units or another grouping variable.

The plot is slow on a large dataset

The bootstrap is the usual cause. Set errorbar=None to skip it, or choose "sd" or "se", which the seaborn error-bars tutorial describes as computed with a formula rather than by bootstrapping. Lowering n_boot from its default of 1000 also reduces the work.

A warning about the ci argument

The ci parameter has been deprecated since seaborn 0.12.0 in favor of errorbar. Code copied from older tutorials with ci=95 or ci="sd" should be rewritten as errorbar=("ci", 95) or errorbar="sd".

Subject lines are missing from the legend

Lines drawn with units get no legend entry, so use hue for the grouping you want in the legend and units for the subject identifier. The legend argument defaults to 'auto'.

Free alternatives

Option How it relates to seaborn line plots
seaborn relplot(kind='line') Figure-level version of the same plot; use it when you want facets
matplotlib Axes.plot() The function that seaborn passes extra keyword arguments to; it draws the lines as given, without aggregation
pandas DataFrame.plot() Plots straight from a DataFrame; the pandas documentation says it uses matplotlib by default, and its default kind is a line plot

All three are open source Python libraries. For related plot types, see scatter plot in Python, and for the wider workflow, Python for exploratory data analysis.

FAQ

What is the difference between a seaborn line plot and a seaborn lineplot?

None. “Line plot” is the plot type and seaborn.lineplot() is the function that draws it. The figure-level alternative is relplot() with kind='line'.

How do I plot multiple lines in seaborn?

Either pass a wide-form DataFrame to data, so each column is a line, or use long-form data and set hue, size or style to a grouping column. For one line per subject, use units with estimator=None.

How do I remove the shaded band?

Set errorbar=None. This also skips the bootstrap computation.

Does seaborn lineplot sort my data?

Yes, by x, unless you pass sort=False.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Seaborn Line Plots: sns.lineplot Syntax, Error Bands and Multiple Lines

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.