我有下面的代码生成下面的图表。除了图例的显示之外,其他一切都是正确的。我想让图例显示每一行的颜色名称,但它只显示我在试图添加图例的代码中出现的第一个变量。另外,%\u ESI_3
的颜色应该是绿色,而不是灰色。
关于如何使用正确的颜色名称将%\u ESI_3
、%\u ESI_4
和%\u ESI_5
添加到图例中,您有何想法?
UMC_Cobmined_Plot.plot(ax=g8, x='Week', y='Total', kind='bar', subplots=True, color='slategray')
UMC_Cobmined_Plot[['%_ESI_3']].plot(ax=g8, secondary_y=True, marker ='d', mark_right=False, color=('green'))
UMC_Cobmined_Plot[['%_ESI_4']].plot(ax=g8, secondary_y=True, marker ='d', mark_right=False, color=('dodgerblue'))
UMC_Cobmined_Plot[['%_ESI_5']].plot(ax=g8, secondary_y=True, marker ='d', mark_right=False, color=('purple'))
g8.set_title('UMC LWBS Acuity % By Volume')
g8.set_ylabel('Total Patients')
g8.right_ax.set_ylabel('% LWBS By Acuity')
g8.tick_params(labelrotation=90)
g8.set_xlabel('')
g8.legend(['%_ESI_3','%_ESI_4','%_ESI_5'],
loc='upper left', frameon=False)
数据样本:
Week Total %_ESI_3 %_ESI_4 %_ESI_5
07/03/2021 470 2.0 4.0 1.0
07/10/2021 477 2.0 3.0 2.0
07/17/2021 517 2.0 6.0 3.0
我必须将我的代码完全更改为此,并且它可以按预期工作:
g8.bar(UMC_Cobmined_Plot['Week'],UMC_Cobmined_Plot['Total'], color='slategray', label = 'Total')
g8.set_ylabel('Total Volume')
g8=g8.twinx()
g8.plot(g8.get_xticks(), UMC_Cobmined_Plot['%_ESI_3'].values, linestyle='-', marker='o', linewidth=2.0, color=('green'))
g8.plot(g8.get_xticks(), UMC_Cobmined_Plot['%_ESI_4'].values, linestyle='-', marker='o', linewidth=2.0, color=('dodgerblue'))
g8.plot(g8.get_xticks(), UMC_Cobmined_Plot['%_ESI_5'].values, linestyle='-', marker='o', linewidth=2.0, color=('purple'))
g8.set_ylabel('% LWBS By Acuity')
g8.set_title('UMC LWBS Acuity % By Volume')
g8.legend(["%_ESI_3", "%_ESI_4","%_ESI_5"])