You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Seaborn散点图中palette参数值"ch:r=-.2,d=.3_r"含义解析

Understanding palette="ch:r=-.2,d=.3_r" in Seaborn's scatterplot

Question Context

Here's the sample scatter plot code from the Seaborn gallery that sparked the question:

# From seaborn gallery - scatter plots
import seaborn as sns 
import matplotlib.pyplot as plt 
sns.set(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", hue_order=clarity_ranking, sizes=(1, 8), linewidth=0, data=diamonds, ax=ax)

The core question: What does the palette="ch:r=-.2,d=.3_r" parameter specifically mean? We know the _r suffix reverses the colormap, but need a full breakdown of the entire string.


Answer

Let’s break down every part of that ch:r=-.2,d=.3_r string so it makes total sense:

  • ch: Prefix: This tells Seaborn to use a Cubehelix colormap. Cubehelix is a smart colormap designed so that even when converted to grayscale, the colors still maintain a clear visual hierarchy. It’s perfect for visualizations that might be printed in black and white or viewed by people with color vision deficiencies.

  • r=-.2: Rotation Parameter: The r stands for rotation. It controls how the hue progresses around the color wheel. A negative value like -0.2 means we’re rotating the hue clockwise slightly from the default starting point (which is usually a warm reddish tone), shifting our colormap’s starting hue toward blue-purples. Positive values would rotate counterclockwise, pushing the hue toward warmer oranges and reds.

  • d=.3: Darkness Parameter: The d is short for darkness. This sets the range of brightness (lightness) across the colormap. A value of 0.3 gives us moderate contrast between the lightest and darkest colors—higher d values make the end of the gradient much darker, while lower values keep the colors more uniformly bright.

  • _r Suffix: As you guessed, this suffix reverses the entire colormap. Instead of the gradient progressing from light to dark (or the default hue order), it flips to dark to light. This can help emphasize different parts of your data depending on your visualization goals.


Content sourced from Stack Exchange, question author: Vim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:57:48