【发布时间】:2019-04-05 18:12:51
【问题描述】:
我使用 python 为一些数据开发了一个条形图。你如何为分类值开发标签?
数据代表 0="Female" 和 1="Male"。开发的条形图仅显示 0 和 1,但我想表示为女性和男性。
使用以下代码,我得到以下输出:
sns.barplot(x=df.cp, y=df.chol, hue=df.sex, palette='spring')
plt.xlabel("Chest Pain Type")
plt.ylabel("Serum Cholesterol")
plt.show()
我尝试将这段代码添加到上面,但输出不符合预期,并且缺少颜色区分:
plt.legend(title="sex", loc="upper right", labels=["Female", "Male"])
谢谢
【问题讨论】:
-
df长什么样子? -
你应该可以做到
sns.barplot(x="cp", y="chol", hue="sex", data=df)。