matplotlib plot bar and line charts together

后端 未结 2 1163
情深已故
情深已故 2020-12-08 17:43

I want to plot bar and line together in one chart. When I plot bars, it displays correctly(g1 and g10 are displayed completed):

However, if I add a line to the plot:

2条回答
  •  一向
    一向 (楼主)
    2020-12-08 18:41

    Try switching the order of plotting:

    ax = m1_t['bad_rate'].plot(secondary_y=True)
    m1_t[['abnormal','fix','normal']].plot(kind='bar', ax=ax)
    

    or preserve the original barchart xlim:

    ax = m1_t[['abnormal','fix','normal']].plot(kind='bar')
    m1_t['bad_rate'].plot(secondary_y=True, xlim=ax.get_xlim())
    

提交回复
热议问题