您更改了绘图的方向但保留了相同的x,y参数,您需要按如下方式进行交换:
plot = sns.factorplot(data=temp, y='seg', x='N', hue='agegroup', row='country', kind='bar',
orient='h', legend=True, aspect=1)
然后图表将水平渲染。
修改强>
要在条形图上方显示标签,这是我能得到的最接近的标签,希望它可以帮助您:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
temp = pd.DataFrame({'country':['A1','A1','A1','A1','A2','A2','A2','A2'],
'seg': ['S1','S2','S1','S2','S1','S2','S1','S2'],
'agegroup': ['1', '2', '2', '1','1', '2', '2', '1'],
'N' : [21,22,23,24,31,32,33,34]})
plot = sns.factorplot(data=temp, y='seg', x='N', hue='agegroup', row='country', kind='bar',
orient='h', legend=True, aspect=1)
ax = plt.gca()
for p in ax.patches:
ax.text(p.get_width(), p.get_y() + p.get_height()/2., '%d' % int(p.get_width()),
fontsize=12, color='red', ha='right', va='center')