Plotnine中的错误栏

时间:2019-03-20 07:08:00

标签: python plotnine

我有以下Python字母代码:

    ggplot(df)
    + geom_point(aes("Distance", "Force"), size=2)
    + geom_path(aes("xfit", "yfit"))

其中Distance,Force,xfit和yfit只是我数据框中的值列表。

这将产生以下情节:

enter image description here

我正在尝试将误差线添加到所有要点。这样做的方法似乎是使用:+ geom_errorbar(),在R中带有ggplot2的代码非常简单:geom_errorbar(ymin = Length - yerr, ymax = Length + yerr)。但是,我无法使用plotine使其在python中工作,并且似乎没有使用错误栏的任何代码示例。

Here is the documentation on the function。但是我没发现有帮助。

1 个答案:

答案 0 :(得分:0)

GitHub上的

TyberiusPrime回答了问题here.,我将在下方粘贴答案,以防它因某些原因从GitHub上消失。我问的问题和这里的完全一样。

在plotine中也很简单,使用字符串代替替代评估。请注意,您已经在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"))

plot with errorbars