Using fill_between () with a Pandas data series

I plotted (using matplotlib) the time series and the bounds of the upper and lower confidence intervals (which I calculated in Stata). I used Pandas to read the output of stata.csv, so the series is of type pandas.core.series.Series.

Matplotlib allows me to display these three episodes in the same plot, but I want to shade between the upper and lower confidence boundaries to create a visual confidence interval. Unfortunately, I am getting an error and the shading does not work. I think this is because the functions I want to populate between are pandas.core.series.Series.

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

+7
python matplotlib pandas
source share
1 answer

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

 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) 

What gives:

enter image description here

+7
source share

All Articles