Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using fill_between() with a Pandas Data Series

I have graphed (using matplotlib) a time series and its associated upper and lower confidence interval bounds (which I calculated in Stata). I used Pandas to read the stata.csv output file and so the series are of type pandas.core.series.Series.

Matplotlib allows me to graph these three series on the same plot, but I wish to shade between the upper and lower confidence bounds to generate a visual confidence interval. Unfortunately I get an error, and the shading doesn't work. I think this is to do with the fact that the functions between which I wish to fill are pandas.core.series.Series.

Another post on here suggests that passing my_series.value instead of my_series will fix this problem; however I cannot get this to work. I'd really appreciate an example.

like image 892
PythonLearner Avatar asked Aug 11 '13 10:08

PythonLearner


1 Answers

As long as you don't have NaN values in your data, you should be okay:

In [78]: x = Series(linspace(0, 2 * pi, 10000))

In [79]: y = sin(x)

In [80]: fill_between(x.values, y.min(), y.values, alpha=0.5)

Which yields:

enter image description here

like image 198
Phillip Cloud Avatar answered Oct 16 '22 18:10

Phillip Cloud