我有以下Python绘图代码:
ggplot(df)
+ geom_point(aes("Distance", "Force"), size=2)
+ geom_path(aes("xfit", "yfit"))其中Distance、Force、xfit和yfit只是我的数据帧中的值列表。
这就产生了这个图:

我正在尝试为所有的点添加错误条。实现这一点的方法似乎是使用:+ geom_errorbar(),这在R和ggplot2中非常简单:geom_errorbar(ymin = Length - yerr, ymax = Length + yerr)。但是,我还不能让它在python中使用plotnine,而且似乎也没有任何使用errorbar的代码示例。
Here is the documentation on the function。不过,我并不觉得它有什么帮助。
发布于 2019-03-21 11:41:50
GitHub上的TyberiusPrime回答了问题here.我将粘贴下面的答案,以防它由于某种原因从GitHub中消失。我在那里问的问题和这里一模一样。
它就像图9中一样直接,使用字符串而不是替代求值。请注意,您已经在geom_point上定义了aes,而不是在绘图上,因此您必须告诉错误栏有关x值的信息。
from plotnine import *
import pandas as pd
df = pd.DataFrame({"Distance": [1,2,3], 'Force': [4,5.5,6], 'yerr': [0.1, 0.5, 3]})
ggplot(df) + geom_point(aes("Distance", "Force"), size=2) + geom_errorbar(aes(x="Distance", ymin="Force-yerr",ymax="Force+yerr"))

https://stackoverflow.com/questions/55255234
复制相似问题