本文介绍了将fill_between()与Pandas数据系列一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已绘制(使用matplotlib)一个时间序列及其相关的置信区间上下限(我在Stata中计算出).我使用Pandas读取stata.csv输出文件,因此该系列的类型为pandas.core.series.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使我可以在同一图上绘制这三个系列的图形,但是我希望在上下置信区间之间加阴影以生成可视置信区间.不幸的是,我得到一个错误,并且阴影不起作用.我认为这与以下事实有关:我要填充的功能是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.

这里的另一篇文章建议传递my_series.value而不是my_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.

推荐答案

只要数据中没有NaN值,就可以了:

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)

哪个产量:

这篇关于将fill_between()与Pandas数据系列一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 19:43