【发布时间】:2020-08-26 04:37:46
【问题描述】:
我希望将条形标签标记在 Y 轴上,而不是条形图的顶部。 有没有办法做到这一点?
我有一段很长的代码来重新创建这个情节,所以只复制它的一部分。我唯一的想法是通过 ax.patches 一个一个来做..
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(12345)
df = pd.DataFrame([np.random.normal(32000,200000,3650),
np.random.normal(43000,100000,3650),
np.random.normal(43500,140000,3650),
np.random.normal(48000,70000,3650)],
index=[1992,1993,1994,1995])
df
....
bar_plot = plt.bar(df.index, df.mean(axis=1),yerr=upper, edgecolor='indigo', color=color)
for i in ax.patches:
ax.text(i.get_x()+0.2, i.get_height()-5.8, \
str(round((i.get_height()), 1)), fontsize=14, color='darkblue')
【问题讨论】:
标签: python matplotlib bar-chart