seaborn.
lineplot
(x=None, y=None, hue=None, size=None, style=None, data=None, palette=None, hue_order=None, hue_norm=None, sizes=None, size_order=None, size_norm=None, dashes=True, markers=None, style_order=None, units=None, estimator='mean', ci=95, n_boot=1000, sort=True, err_style='band', err_kws=None, legend='brief', ax=None, **kwargs)¶Draw a line plot with possibility of several semantic groupings.
The relationship between x
and y
can be shown for different subsets
of the data using the hue
, size
, and style
parameters. These
parameters control what visual semantics are used to identify the different
subsets. It is possible to show up to three dimensions independently by
using all three semantic types, but this style of plot can be hard to
interpret and is often ineffective. Using redundant semantics (i.e. both
hue
and style
for the same variable) can be helpful for making
graphics more accessible.
See the tutorial for more information.
By default, the plot aggregates over multiple y
values at each value of
x
and shows an estimate of the central tendency and a confidence
interval for that estimate.
Parameters: | x, y : names of variables in
hue : name of variables in
size : name of variables in
style : name of variables in
data : DataFrame
palette : palette name, list, or dict, optional
hue_order : list, optional
hue_norm : tuple or Normalize object, optional
sizes : list, dict, or tuple, optional
size_order : list, optional
size_norm : tuple or Normalize object, optional
dashes : boolean, list, or dictionary, optional
markers : boolean, list, or dictionary, optional
style_order : list, optional
units : {long_form_var}
estimator : name of pandas method or callable or None, optional
ci : int or “sd” or None, optional
n_boot : int, optional
sort : boolean, optional
err_style : “band” or “bars”, optional
err_band : dict of keyword arguments
legend : “brief”, “full”, or False, optional
ax : matplotlib Axes, optional
kwargs : key, value mappings
|
---|---|
Returns: | ax : matplotlib Axes
|
See also
scatterplot
x
variable.pointplot
Examples
Draw a single line plot with error bands showing a confidence interval:
>>> import seaborn as sns; sns.set()
>>> import matplotlib.pyplot as plt
>>> fmri = sns.load_dataset("fmri")
>>> ax = sns.lineplot(x="timepoint", y="signal", data=fmri)
Group by another variable and show the groups with different colors:
>>> ax = sns.lineplot(x="timepoint", y="signal", hue="event",
... data=fmri)
Show the grouping variable with both color and line dashing:
>>> ax = sns.lineplot(x="timepoint", y="signal",
... hue="event", style="event", data=fmri)
Use color and line dashing to represent two different grouping variables:
>>> ax = sns.lineplot(x="timepoint", y="signal",
... hue="region", style="event", data=fmri)
Use markers instead of the dashes to identify groups:
>>> ax = sns.lineplot(x="timepoint", y="signal",
... hue="event", style="event",
... markers=True, dashes=False, data=fmri)
Show error bars instead of error bands and plot the standard error:
>>> ax = sns.lineplot(x="timepoint", y="signal", hue="event",
... err_style="bars", ci=68, data=fmri)
Show experimental replicates instead of aggregating:
>>> ax = sns.lineplot(x="timepoint", y="signal", hue="event",
... units="subject", estimator=None, lw=1,
... data=fmri.query("region == 'frontal'"))
Use a quantitative color mapping:
>>> dots = sns.load_dataset("dots").query("align == 'dots'")
>>> ax = sns.lineplot(x="time", y="firing_rate",
... hue="coherence", style="choice",
... data=dots)
Use a different normalization for the colormap:
>>> from matplotlib.colors import LogNorm
>>> ax = sns.lineplot(x="time", y="firing_rate",
... hue="coherence", style="choice",
... hue_norm=LogNorm(), data=dots)
Use a different color palette:
>>> ax = sns.lineplot(x="time", y="firing_rate",
... hue="coherence", style="choice",
... palette="ch:2.5,.25", data=dots)
Use specific color values, treating the hue variable as categorical:
>>> palette = sns.color_palette("mako_r", 6)
>>> ax = sns.lineplot(x="time", y="firing_rate",
... hue="coherence", style="choice",
... palette=palette, data=dots)
Change the width of the lines with a quantitative variable:
>>> ax = sns.lineplot(x="time", y="firing_rate",
... size="coherence", hue="choice",
... legend="full", data=dots)
Change the range of line widths used to normalize the size variable:
>>> ax = sns.lineplot(x="time", y="firing_rate",
... size="coherence", hue="choice",
... sizes=(.25, 2.5), data=dots)
Plot from a wide-form DataFrame:
>>> import numpy as np, pandas as pd; plt.close("all")
>>> index = pd.date_range("1 1 2000", periods=100,
... freq="m", name="date")
>>> data = np.random.randn(100, 4).cumsum(axis=0)
>>> wide_df = pd.DataFrame(data, index, ["a", "b", "c", "d"])
>>> ax = sns.lineplot(data=wide_df)
Plot from a list of Series:
>>> list_data = [wide_df.loc[:"2005", "a"], wide_df.loc["2003":, "b"]]
>>> ax = sns.lineplot(data=list_data)
Plot a single Series, pass kwargs to plt.plot
:
>>> ax = sns.lineplot(data=wide_df["a"], color="coral", label="line")
Draw lines at points as they appear in the dataset:
>>> x, y = np.random.randn(2, 5000).cumsum(axis=1)
>>> ax = sns.lineplot(x=x, y=y, sort=False, lw=1)