鉴于
df
作为数据帧,我只是试图复制您提供的示例。在我看来,轮换
y
fig = plt.figure(figsize=(10, 6))
ax = df.plot.barh(y='tracks_sold', x='genre', color='mediumseagreen', ec='k', lw=1)
plt.xlim(0, 630)
plt.yticks(rotation=30)
plt.ylabel('')
plt.title('Top Selling Genres in the USA')
ax.legend_.remove()
# Way 1 of putting percentage values
for i in range(len(df)):
ax.text(tracks_sold[i] + 5, 0.98*i, str(int(percentage[i])) + '%', color='black', fontweight='bold')
# Way 2 of putting percentage values
# for i, p in enumerate(ax.patches):
# ax.annotate(str(int(percentage[i])) + '%', (p.get_width() * 1.02, i))