如何固定颜色设置
如用seaborn画分类散点图,用hue分类
第一张红色的点代表事业部
第二张红色的点又代表机关
第三张红色的点又代表保障部门
如何固定下来
红色代表 事业部
蓝色代表 机关
灰色代表保障部门
seaborn画分类散点图,hue自动配合颜色一直在变
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
CSDN专家-HGJ 2021-10-13 01:14关注使用scatterplot中的参数palette进行设置,类似如下示例:
import seaborn as sns import matplotlib.pyplot as plt sns.set_theme(style="whitegrid") # Load the example diamonds dataset diamonds = sns.load_dataset("diamonds") # Draw a scatter plot while assigning point colors and sizes to different # variables in the dataset f, ax = plt.subplots(figsize=(6.5, 6.5)) sns.despine(f, left=True, bottom=True) clarity_ranking = ["I1", "SI2", "SI1", "VS2", "VS1", "VVS2", "VVS1", "IF"] sns.scatterplot(x="carat", y="price", hue="clarity", size="depth", #palette="ch:r=-.2,d=.3_r", palette=['red','green','blue','orange','yellow','cyan','pink','purple'], hue_order=clarity_ranking, sizes=(1, 8), linewidth=0, data=diamonds, ax=ax) plt.show()如有帮助,请采纳。点击我回答右上角【采纳】按钮。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报