我需要两张折线图&;同一图表中的条形图。两个折线图的y轴相同, 但是条形图有一个不同的轴
表格格式
Indicator Name 2011 2012 2013 2014 2015 2016 2017 2018 2019
Bank nonperforming loans to total gross loans (%) 3.8 3.6 5.5 4.2 3.2 2.6 2.4 3.4 4.2
Bank nonperforming loans to total net loans (%) 3 2.2 3.8 2.6 1.2 1.7 1.3 2.2 2.5
Bank Total gross loans ( LK Bn) 99 116.6 191 165 152.8 142.3 160.7 263.1 275.5
这是我的代码:
df.loc['Bank nonperforming loans to total gross loans (%)', years].plot(kind = 'line',color='mediumvioletred',marker ='o',
markerfacecolor ='blue',markersize=9,label = "NPL %")
df.loc['Bank nonperforming loans to total net loans (%)', years].plot(kind = 'line',color='blue',label = "SL")
plt.twinx()
df.loc['Bank Total gross loans (LK Bn)', years].plot(kind = 'Bar',color='brown',label = "chk")
plt.ylim([90,280])
plt.title('Immigration from Afghanistan')
plt.ylabel('NPL %')
plt.xlabel('years')
plt.legend()
下面是我得到的图表,但它没有显示条形图
您的案例需要比
DataFrame.plot
提供的更多控制。您需要定义绘图的顺序:线条应位于条形图的顶部,但另外,条形图位于双轴上,这会产生另一个问题。以下是您的问题的解决方案,主要基于此answer代码:
绘图:
相关问题 更多 >
编程相关推荐