【发布时间】:2021-12-31 15:41:12
【问题描述】:
我创建了一个条形图,并希望将计数值放在每个条形上方。
# Import the libraries
import pandas as pd
from matplotlib import pyplot as plt
# Create the DataFrame
df = pd.DataFrame({
'city_code':[1200013, 1200104, 1200138, 1200179, 1200203],
'index':['good', 'bad', 'good', 'good', 'bad']
})
# Plot the graph
df['index'].value_counts().plot(kind='bar', color='darkcyan',
figsize=[15,10])
plt.xticks(rotation=0, horizontalalignment="center", fontsize=14)
plt.ylabel("cities", fontsize=16)
我得到以下结果
我想在每个栏的顶部添加值。我从 value_counts 得到的 count 的值。 像这样的:
感谢所有提供帮助的人。
【问题讨论】:
标签: python pandas matplotlib graph