5

Consider the examples for tsplot (time-series plot) in seaborn, e.g. the one shown below.

Do pandas, matplotlib or seaborn include similar functionality to plot translucent bands representing percentiles or standard deviations of a population provided in a dataframe?

Reading the documentation, it looks like sns.tsplot plots confidence intervals for the sampling distribution of the estimator via bootstrapping, which is of course different.

enter image description here

Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564

2 Answers2

2

Worth mentioning that the proposal by raphael conflates percentiles and confidence intervals, which are very different statistics. For example, if you use ci=[0,100] in tsplot, you will not get bands showing the minimum and maximum of your data. An issue requesting inclusion of percentiles was raised on the Seaborn github page in January 2016, with a clear--and curt--reply that this was not currently possible.

A potential work-around has been posted here.

David Diaz
  • 437
  • 4
  • 11
-1

From the seaborn tsplot documentation, it seems you can provide multiple percentile confidence bands. The example below plots the 68th percentile and 95th percentile confidence bands (ci=[68, 95]). You can also change the value of the line to, for example, the median with estimator=np.median or np.mean.

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, ci=[68, 95], color="m")

raphael
  • 2,762
  • 5
  • 26
  • 55