【发布时间】:2022-01-17 08:14:01
【问题描述】:
通过以下代码,我可以使用 seaborn 的散点图来绘制数据,并将某些颜色分配给数据值。
如何设置此示例中使用的颜色数量? (例如,如果我只想使用两种颜色或多于示例中显示的 6 种颜色)
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset('tips')
print("tips.columns=", tips.columns) # tips.columns= Index(['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size'], dtype='object')
sns.scatterplot(data=tips, x="total_bill", y="tip", hue="total_bill", )
【问题讨论】:
-
Seaborn 的
scatterplot有一个legend=关键字,可以是'auto'。'brief'。'full'或False。如果你想要别的东西,你需要创建一个自定义图例。 -
感谢您的建议。但它不应该是影响颜色数量的色相参数本身吗?因为如果我省略图例,我仍然希望拥有 e。 G。只有两种颜色。
-
听起来很值得enhance request on seaborn,我鼓励你提交。
标签: python seaborn scatter-plot