I’m using ggplot in python with plotnine, I have this piece of code:
JavaScript
x
11
11
1
my_plot_availability = (ggplot(df)
2
+ aes(x='time_elapsed',y='mean',fill='policy')
3
+ geom_bar(position=position_dodge(),stat = "identity", color = "black",size = 0.5)
4
+ geom_errorbar(aes(ymin='mean-error', ymax='mean+error'), width=.2,position=position_dodge(.9))
5
+ facet_wrap('mobility')
6
+ scale_fill_manual(["darkgray", "gray"])
7
+ labs(x = "Time elpased [s]")
8
+ labs(y = "Mean content availability")
9
+ theme(element_text(family="Times",size=12))
10
)
11
that plots this figure:
And I want to have the same size bars, even if in some cases like case 0 there is only one bar. I know I should do it with:
JavaScript
1
2
1
position=position_dodge2(preserve='single')
2
But I’m getting the following error in python:
JavaScript
1
2
1
NameError: name 'position_dodge2' is not defined
2
Do you know how to solve this?
Advertisement
Answer
You need to upgrade your version of plotnine to v0.6.0.