如何使用 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 (将#修改为@)