seaborn.tsplot(data, time=None, unit=None, condition=None, value=None, err_style='ci_band', ci=68, interpolate=True, color=None, estimator=<function mean>, n_boot=5000, err_palette=None, err_kws=None, legend=True, ax=None, **kwargs)

Plot one or more timeseries with flexible representation of uncertainty.

This function is intended to be used with data where observations are nested within sampling units that were measured at multiple timepoints.

It can take data specified either as a long-form (tidy) DataFrame or as an ndarray with dimensions (unit, time) The interpretation of some of the other parameters changes depending on the type of object passed as data.


data : DataFrame or ndarray

Data for the plot. Should either be a “long form” dataframe or an array with dimensions (unit, time, condition). In both cases, the condition field/dimension is optional. The type of this argument determines the interpretation of the next few parameters. When using a DataFrame, the index has to be sequential.

time : string or series-like

Either the name of the field corresponding to time in the data DataFrame or x values for a plot when data is an array. If a Series, the name will be used to label the x axis.

unit : string

Field in the data DataFrame identifying the sampling unit (e.g. subject, neuron, etc.). The error representation will collapse over units at each time/condition observation. This has no role when data is an array.

value : string

Either the name of the field corresponding to the data values in the data DataFrame (i.e. the y coordinate) or a string that forms the y axis label when data is an array.

condition : string or Series-like

Either the name of the field identifying the condition an observation falls under in the data DataFrame, or a sequence of names with a length equal to the size of the third dimension of data. There will be a separate trace plotted for each condition. If condition is a Series with a name attribute, the name will form the title for the plot legend (unless legend is set to False).

err_style : string or list of strings or None

Names of ways to plot uncertainty across units from set of {ci_band, ci_bars, boot_traces, boot_kde, unit_traces, unit_points}. Can use one or more than one method.

ci : float or list of floats in [0, 100] or “sd” or None

Confidence interval size(s). If a list, it will stack the error plots for each confidence interval. If "sd", show standard deviation of the observations instead of boostrapped confidence intervals. Only relevant for error styles with “ci” in the name.

interpolate : boolean

Whether to do a linear interpolation between each timepoint when plotting. The value of this parameter also determines the marker used for the main plot traces, unless marker is specified as a keyword argument.

color : seaborn palette or matplotlib color name or dictionary

Palette or color for the main plots and error representation (unless plotting by unit, which can be separately controlled with err_palette). If a dictionary, should map condition name to color spec.

estimator : callable

Function to determine central tendency and to pass to bootstrap must take an axis argument.

n_boot : int

Number of bootstrap iterations.

err_palette : seaborn palette

Palette name or list of colors used when plotting data for each unit.

err_kws : dict, optional

Keyword argument dictionary passed through to matplotlib function generating the error plot,

legend : bool, optional

If True and there is a condition variable, add a legend to the plot.

ax : axis object, optional

Plot in given axis; if None creates a new figure

kwargs :

Other keyword arguments are passed to main plot() call


ax : matplotlib axis

axis with plot data


Plot a trace with translucent confidence bands:

>>> import numpy as np; np.random.seed(22)
>>> import seaborn as sns; sns.set(color_codes=True)
>>> x = np.linspace(0, 15, 31)
>>> data = np.sin(x) + np.random.rand(10, 31) + np.random.randn(10, 1)
>>> ax = sns.tsplot(data=data)

Plot a long-form dataframe with several conditions:

>>> gammas = sns.load_dataset("gammas")
>>> ax = sns.tsplot(time="timepoint", value="BOLD signal",
...                 unit="subject", condition="ROI",
...                 data=gammas)

Use error bars at the positions of the observations:

>>> ax = sns.tsplot(data=data, err_style="ci_bars", color="g")

Don’t interpolate between the observations:

>>> import matplotlib.pyplot as plt
>>> ax = sns.tsplot(data=data, err_style="ci_bars", interpolate=False)

Show multiple confidence bands:

>>> ax = sns.tsplot(data=data, ci=[68, 95], color="m")

Show the standard deviation of the observations:

>>> ax = sns.tsplot(data=data, ci="sd")

Use a different estimator:

>>> ax = sns.tsplot(data=data, estimator=np.median)

Show each bootstrap resample:

>>> ax = sns.tsplot(data=data, err_style="boot_traces", n_boot=500)

Show the trace from each sampling unit:

>>> ax = sns.tsplot(data=data, err_style="unit_traces")