Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Seaborn · Function

lineplot

seaborn.lineplot draws a line chart for an x–y relationship and can distinguish subsets with color, width, and style. It aggregates repeated observations by default and shows an estimate with uncertainty.

How it works

lineplot maps variables to line position and can distinguish subsets with color, width, and style. When multiple y observations share an x value, it aggregates them by default and displays a central estimate with an uncertainty interval.

Syntax

seaborn.lineplot(data=None, *, x=None, y=None, hue=None, size=None, style=None, units=None, weights=None, palette=None, hue_order=None, hue_norm=None, sizes=None, size_order=None, size_norm=None, dashes=True, markers=None, style_order=None, estimator='mean', errorbar=('ci', 95), n_boot=1000, seed=None, orient='x', sort=True, err_style='band', err_kws=None, legend='auto', ci='deprecated', ax=None, **kwargs)

Parameters

NameTypeDescription
datapandas.DataFrame, numpy.ndarray, mapping, or sequenceInput data structure.
x, yvectors or keys in dataVariables that specify positions on the x and y axes.
huevector or key in dataGrouping variable that will produce lines with different colors.
sizevector or key in dataGrouping variable that will produce lines with different widths.
stylevector or key in dataGrouping variable that will produce lines with different dashes and/or markers.
unitsvector or key in dataGrouping variable that will produce separate lines without affecting line appearance.
estimatorname of pandas method, callable, or NoneMethod for aggregating over observations.
errorbarstring, tuple, callable, or NoneMethod for calculating the uncertainty estimate.
axmatplotlib.axes.AxesAxes object to draw the plot onto.

Returns

Returns the Axes object with the plot drawn onto it.

Key points

  • Use lineplot to visualize a relationship between two variables while representing subsets through semantic mappings.
  • The same x–y relationship can be split into multiple subset-specific lines.
  • hue, size, and style determine how subsets are visually identified.
  • Three additional dimensions can be encoded independently with hue, size, and style.
  • The default display combines a central-tendency estimate with a confidence interval.

Common mistakes

  • Using hue, size, and style simultaneously can encode three dimensions, but the resulting chart may be difficult to interpret.
  • Repeated y values for an x coordinate are summarized rather than drawn as independent observations; disable aggregation with an appropriate estimator setting.

Example: Grouped line plot

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="whitegrid")
data = {"time": [1, 2, 3, 1, 2, 3], "value": [2, 4, 3, 1, 3, 5], "group": ["A", "A", "A", "B", "B", "B"]}
sns.lineplot(data=data, x="time", y="value", hue="group", marker="o")
plt.show()

Plots the mean value at each time for two groups, using color and markers to distinguish them.

When to use it

Show change over time or another ordered continuous variable.

Continuous progression

Compare trajectories for subsets using hue, size, or style.

Grouped trends

Display an aggregated trend together with its confidence interval.

Uncertainty visualization

Interview questions

QWhat is seaborn.lineplot used for?

lineplot draws a relationship between x and y and supports semantic grouping through hue, size, and style. It can show separate subsets of the data while varying color, line width, or line pattern.

Follow-up: How can three additional variables be represented? Use hue, size, and style independently, while checking that the combined encodings remain interpretable.

QWhat happens when multiple observations share the same x value?

With repeated y observations at an x value, the function aggregates them by default. It shows an estimate of central tendency together with a confidence interval.

Follow-up: What should you consider when interpreting the line? Determine whether the aggregation and uncertainty interval match the question, rather than treating the line as every raw observation.

QWhich parameters control grouping and uncertainty?

The function accepts x and y variables plus an optional data structure, and hue can produce differently colored lines for groups. The current signature also exposes controls such as estimator, errorbar, sorting, and legend behavior.

Follow-up: How would you make group distinctions more explicit? Combine semantic mappings selectively, for example hue with style, and use ordering parameters when the displayed order matters.

  • seaborn.scatterplot
  • seaborn.relplot
  • seaborn.set_theme
  • seaborn.load_dataset

Source: seaborn.lineplot — seaborn 0.13.2 documentation. Checked 2026-10-15.