Plotnine,改变 x 轴上月份的顺序,目前按字母顺序排列

发布于 2025-01-17 22:29:49 字数 389 浏览 4 评论 0原文

使用 Plotnine 绘制每月的值。 目前,月份在 x 轴上按字母顺序排序。 如何改变这一点?

这是代码:

(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)))

和情节: 输入图片此处描述

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

来日方长 2025-01-24 22:29:49

刚刚找到解决方案:

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)))

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)))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文