代码之家  ›  专栏  ›  技术社区  ›  bbartling

显示一个传说熊猫绘制多个Y轴

  •  0
  • bbartling  · 技术社区  · 3 年前

    有人能给我一个建议,告诉我如何在情节中加入传奇吗?我很高兴剧情看起来只是需要一个传说:)

    # data from pandas df's
    zoom_plot = fc1_dataset.loc['2021-8-9'].between_time('5:00', '17:00')
    _no_vfd_sig = zoom_plot[['fc1_flag','duct_static','duct_static_setpoint']]
    _vfdsig = zoom_plot.vfd_speed
    
    
    # using subplots() function
    fig, ax = plt.subplots(figsize=(25,8))
    plt.title('Visually verify FDD is flagging OK')
     
    # using the twinx() for creating another
    # axes object for secondary y-Axis
    ax2 = ax.twinx()
    ax.plot(zoom_plot.index, _no_vfd_sig)
    ax2.plot(zoom_plot.index, _vfdsig, color = 'r')
     
    # giving labels to the axises
    ax.set_xlabel('Date')
    ax.set_ylabel('Duct Pressure and FDD Flag')
    
    # secondary y-axis label
    ax2.set_ylabel('% Fan Speed')
    
    # defining display layout
    plt.tight_layout()
     
    # show plot
    plt.show()
    

    输出 enter image description here

    0 回复  |  直到 3 年前
        1
  •  1
  •   tzinie    3 年前

    与之前的代码相同。。。

    plot1, = ax.plot(zoom_plot.index, _no_vfd_sig)
    plot2, = ax2.plot(zoom_plot.index, _vfdsig, color = 'r')
    
    ax.set_xlabel('Date')
    ax.set_ylabel('Duct Pressure and FDD Flag')
    
    # secondary y-axis label
    ax2.set_ylabel('% Fan Speed')
    
    plt.legend([plot1,plot2],["plot 1", "plot 2"])
    
    # defining display layout
    plt.tight_layout()
    
    # show plot
    plt.show()