微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 Plotnine 在 GridSpec 中旋转刻度标签?

如何解决如何使用 Plotnine 在 GridSpec 中旋转刻度标签?

我正在尝试旋转 x 轴的刻度以使我的图形可读。我将在下面展示我的代码,但总而言之,我使用 plotnine 创建图形,然后使用 Gridspec 组合 4 个图形。

x 轴代表年,但它们挤在一起,所以不可读。

我的代码

#PLot the graphs using plotnine
p1 = (ggplot(CRev_All_age1) + aes(x='YearOnboarded',y='Revenue',group='factor(age_buckets)',fill='age_buckets')+ geom_bar(stat='identity',alpha=0.8,show_legend=True) + labs(title='Client Revenue - Overall Age Group (Million)'))
p2 = (ggplot(Plot_CRev_EU_age1) + aes(x='YearOnboarded',show_legend=True) + labs(title='Europe - Client Revenue By Year Onboarded (Million)'))
p3 = (ggplot(Plot_CRev_Asia_age1) + aes(x='YearOnboarded',show_legend=True) + labs(title='Asia - Client Revenue By Year Onboarded (Million)'))
p4 = (ggplot(Plot_CRev_Other_age1) + aes(x='YearOnboarded',show_legend=True) + labs(title='Other Continents - Client Revenue By Year Onboarded (Million)'))

# Empty plotnine figure to place the subplots on. Needs junk data (for backend "copy" reasons).
fig = (ggplot()+ geom_blank(data=df_optimized)+ theme_void()).draw()

# Create gridspec for adding subpanels to the blank figure
gs = gridspec.GridSpec(nrows=2,ncols=2,wspace=0.4,hspace=0.3,width_ratios=(20,20),height_ratios=(7,7))
ax1 = fig.add_subplot(gs[0,0])
ax1.set_title('Overall - Client Revenue',fontsize=10)
ax2 = fig.add_subplot(gs[0,1])
ax2.set_title('Europe - Client Revenue',fontsize=10)
ax3 = fig.add_subplot(gs[1,0])
ax3.set_title('Asia - Client Revenue',fontsize=10)
ax4 = fig.add_subplot(gs[1,1])
ax4.set_title('Other Continents - Client Revenue',fontsize=10)

# Add subplots to the figure
_ = p1._draw_using_figure(fig,[ax1])
_ = p2._draw_using_figure(fig,[ax2])
_ = p3._draw_using_figure(fig,[ax3])
_ = p4._draw_using_figure(fig,[ax4])

fig.show()

我尝试使用这个问题的答案: Rotate tick labels in subplot (Pyplot,Matplotlib,gridspec) 但他们都没有为我工作。 有谁知道我如何解决这个问题?谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。