Plotnine, changing order of Months on x axis, currently alphabetically

571 Views Asked by At

Using Plotnine to plot values per month. Currently, the Months are ordered alphabetically on x axis. How to change this?

here is the code:

(ggplot(df, aes(x = 'Month', y='Rented Bike Count')) + 
stat_summary(fun_data = 'mean_sdl', geom = 'bar') +
theme(axis_text_x = element_text(angle=90)))

and the plot: enter image description here

1

There are 1 best solutions below

1
On

just found out the solution:

months = ["January", "February", "March", "April", "May", "June", 
          "July", "August", "September", "October", "November", "December"]
(ggplot(df, aes(x = 'Month', y='Rented Bike Count')) + 
stat_summary(fun_data = 'mean_sdl', geom = 'bar') +
scale_x_discrete(limits=months) +
theme(axis_text_x = element_text(angle=90)))