gpt4 book ai didi

python - Pandas 区域图插值/步骤样式

转载 作者:太空狗 更新时间:2023-10-30 02:29:59 25 4
gpt4 key购买 nike

有没有办法禁用 pandas 区域图中的插值?我想得到一个“阶梯式”面积图。例如。在法线图中可以指定:

import pandas as pd
df = pd.DataFrame({'x':range(10)})
df.plot(drawstyle = 'steps') # this works
#df.plot(kind = 'area', drawstyle = 'steps') # this does not work

我正在使用 python 2.7 和 pandas 0.14.1。

非常感谢。

最佳答案

最近 update .fill_between()ma​​tplotlib 1.5.0 版 一起提供,允许填充两个阶跃函数之间的区域。这甚至适用于 Pandas 时间序列。

由于参数 step='pre' 存在,所以可以这样使用:

# For error bands around a series df
ax.fill_between(df.index, df - offset, df + offset, step='pre', **kwargs)

# For filling the whole area below a function
ax.fill_between(df.index, df, 0, step='pre', **kwargs)

对我来说有意义的其他关键字参数例如 alpha=0.3lw=0

关于python - Pandas 区域图插值/步骤样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29808660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com