【问题标题】:Is position_dodge2() working for python with plotnine?position_dodge2() 是否适用于带有 plotnine 的 python?
【发布时间】:2019-12-13 17:12:13
【问题描述】:

我在 python 中使用 ggplot 和 plotnine,我有这段代码:

my_plot_availability = (ggplot(df)         
+ aes(x='time_elapsed',y='mean',fill='policy')    
+ geom_bar(position=position_dodge(),stat = "identity", color = "black",size = 0.5)
+ geom_errorbar(aes(ymin='mean-error', ymax='mean+error'), width=.2,position=position_dodge(.9))
+ facet_wrap('mobility')
+ scale_fill_manual(["darkgray", "gray"])
+ labs(x = "Time elpased [s]") 
+ labs(y = "Mean content availability")
+ theme(element_text(family="Times",size=12))
)

绘制这个图:

而且我希望有相同大小的条形图,即使在某些情况下(例如案例 0)只有一个条形图。我知道我应该这样做:

position=position_dodge2(preserve='single')

但我在 python 中遇到以下错误:

NameError: name 'position_dodge2' is not defined

你知道怎么解决吗?

【问题讨论】:

    标签: python ggplot2 geom-bar python-ggplot plotnine


    【解决方案1】:

    您需要将您的 plotnine 版本升级到 v0.6.0。

    【讨论】:

    • 我做到了,现在我得到:ValueError: Unknown distribution 'logistic'
    • 我在这里检查了github.com/has2k1/plotnine/issues/71,但它被关闭了,没有解决方案。
    • @BlueMountain,您的环境和软件包可能混淆了,plotnine 可能使用的是旧版本的 scipy。
    猜你喜欢
    • 1970-01-01
    • 2022-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多