如何在matplotlib中将垂直线添加到条形图中

2024-10-05 11:38:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码:

ax = df30_pivoted.plot(kind='bar', figsize=(30,20), linewidth=5)
plt.xticks(rotation='vertical')
plt.tick_params(labelsize=20)
plt.xlabel('session_date', fontsize=20)
plt.grid(True)
plt.title('', fontdict={'fontsize':60})
legend = ax.legend(loc=0, ncol=1, bbox_to_anchor=(0,1,1), fancybox=True, shadow=False, title='variations', prop={'size':45})


xposition = c12
for xc in xposition:
    ax.axvline(x=xc, color='r', linewidth=4)
plt.setp(legend.get_title(), fontsize='30')

plt.show()

我希望上面的代码put vertical line在x轴上的索引与我在c12中的索引相同,c12是一个pandas系列,类型为datetime64[ns],但结果条形图没有垂直线:

enter image description here


Tags: 代码trueplottitlepltaxlegendxc

热门问题