条形图上的条形图值

时间:2020-09-26 03:26:33

标签: matplotlib

我的条形图图形具有较大的计数值,并显示水平条形图的顶部,由于计数值巨大,这些值重叠并且占用较大的面积.. i want like this ,counts are displaying vertical

1 个答案:

答案 0 :(得分:1)

尝试一下:

df = pd.DataFrame({'dates':pd.date_range('2020-09-10', periods=10), 'trades':np.random.randint(40000,99999, 10)})

ax = df.plot.bar(x='dates', y='trades')
for p in ax.patches:
    ax.annotate("%.2f" % p.get_height(), (p.get_x() + p.get_width() / 2., p.get_height()/2),
                 ha='center', va='center', fontsize=11, color='w', xytext=(0, 5),
                 textcoords='offset points', rotation=90)
ax.set_xticklabels(df['dates'].dt.strftime('%m/%d/%Y'));

输出:

enter image description here