我有2组数据需要将它们组合在一起。
我有以下代码来生成条形图:
table = pd.crosstab(data['Gender'],data['I have flirted with someone at work before'])
table.div(table.sum(1).astype(float), axis=0).plot(kind='bar', stacked=True)
plt.title('Relationship between gender and flirting behaviour',fontweight='bold')
plt.xlabel('Gender')
plt.ylabel('Flirting behaviour')
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
bars = ('Female', 'Male')
y_pos = np.arange(len(bars))
plt.xticks(y_pos,bars, color='black', rotation=0, fontweight='normal',
fontsize='12', horizontalalignment='center')
它生成以下图:
但是,我希望条形图中包含相应的百分比。
例如 :
我该怎么做?