【发布时间】:2019-07-01 16:22:30
【问题描述】:
我使用 sns.countplot 生成的绘图带有使用“hue”参数的图例。我想在图例中显示“类别”计数的频率,以及“Cross_Tab”标签:
df数据:
Category Cross_Tab
Apple Yes
Apple No
Peach Yes
Peach No
Dog Yes
Dog Yes
剧情:
fig = sns.countplot(x="Category", hue="Cross_Tab", data=dfData, order=dfData.Category.value_counts().index)
传说:
fig.legend(title="This is the Legend", loc='upper right')
这只是显示图例类别:
"This is the Legend"
Yes
No
期望的输出: 剧情的传说应该是这样的:
"This is the Legend"
Yes (n = 4)
No (n = 2)
查看各种来源后 - 我已经做到了,但它不起作用:
x = dfData.Cross_Tab.value_counts()
fig.legend("n=(%s)"%(x, ), title="This is the Legend", loc='upper right')
【问题讨论】:
标签: python matplotlib seaborn