【发布时间】:2022-01-05 09:17:01
【问题描述】:
如何获得每个条右侧的计数和百分比???目前我只知道如何计算。
import pandas as pd
import matplotlib.pyplot as plt
age = ['0-17','18-60','61-80']
df3 = pd.DataFrame(data={'Male':[82,550,25], 'Female':[72,309,7]}, index=age)
print(df3)
ax = df3.plot(kind='barh', ylabel='Age', title='Passenger Count by Age and Sex')
ax.set(xlabel='No. of Passengers')
for c in ax.containers:
# set the bar label
ax.bar_label(c, fmt='%.0f', label_type='edge')
ax.legend(title='Sex', bbox_to_anchor=(1, 1.02), loc='upper left')
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
plt.show()
【问题讨论】:
标签: python pandas matplotlib annotations bar-chart