Python 3.x 在python中在多个子地块上绘制次轴
我试图在条形图的所有子图的次轴上绘图,但我只成功地在其中一个子图上显示了次绘图(参见下图)。 我试过:Python 3.x 在python中在多个子地块上绘制次轴,python-3.x,Python 3.x,我试图在条形图的所有子图的次轴上绘图,但我只成功地在其中一个子图上显示了次绘图(参见下图)。 我试过: df[['loan_amnt','int_rate']].plot(kind='bar',subplots=True,layout=(1,2), figsize=(15,5)) df['dti'].plot(secondary_y=True, marker='d', style='g:'); 并得到如下所示: 我可以向该代码中添加哪些内容以确保二次绘图显示在两个子绘图上。我可以使用以下代码
df[['loan_amnt','int_rate']].plot(kind='bar',subplots=True,layout=(1,2), figsize=(15,5))
df['dti'].plot(secondary_y=True, marker='d', style='g:');
并得到如下所示:
我可以向该代码中添加哪些内容以确保二次绘图显示在两个子绘图上。我可以使用以下代码解决此问题:
fig = plt.figure(figsize=(15,5))
cx0 = fig.add_subplot(121)
cx1 = cx0.twinx()
cx2 = plt.subplot(122)
cx3 = cx2.twinx()
rate_amnt_byGrade['loan_amnt'].plot(kind='bar', ax=cx0)
rate_amnt_byGrade['dti'].plot(ax=cx1, secondary_y=True)
rate_amnt_byGrade['int_rate'].plot(kind='bar', ax=cx2)
rate_amnt_byGrade['dti'].plot(ax=cx3, secondary_y=True)
我也尝试过使用for循环,但它不起作用。请有人帮我回答这个问题。