此字符串在seaborn散点图的Palette参数中意味着什么?

时间:2019-04-09 14:21:10

标签: python matplotlib plot seaborn

seaborn gallery - scatter plots

import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")

# Load the example iris 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)

这个神秘的字符串"ch:r=-.2,d=.3_r"是什么意思?

我唯一能找到的参考文献是seaborn.color_palette的文档,

Other options:
  name of matplotlib cmap, 'ch:<cubehelix arguments>', 'hls', 'husl', or a list 
  of colors in any format matplotlib accepts

但是仍然无法在matplotlib文档中找到任何内容。

那么,这到底是什么意思?到目前为止,我只知道后缀_r表示色调的“反向”。

1 个答案:

答案 0 :(得分:1)

from django.db import models from django.utils import timezone # Create your models here. class Comment(models.Model): name=models.CharField(max_length=20) comments=models.TextField() date_added=models.DateTimeField(default=timezone.now) def __str__(self): return self.name """ {% for c in comment %} {% endfor %} """ 语法特定于Seaborn。因此,难怪matplotlib文档中对此一无所知。

"ch:r=-.2,d=.3_r"<cubehelix arguments>的可能选项可以  从seaborn.cubehelix_palette文档中隐式推导。

这提供了

之类的参数
'ch:<cubehelix arguments>'

您可以在字符串中使用

start : float, 0 <= start <= 3
          The hue at the start of the helix.
rot : float
          Rotations around the hue wheel over the range of the palette.
gamma : float 0 <= gamma
          Gamma factor to emphasize darker (gamma < 1) or lighter (gamma > 1) colors.
hue : float, 0 <= hue <= 1
          Saturation of the colors.
dark : float 0 <= dark <= 1
          Intensity of the darkest color in the palette.
light : float 0 <= light <= 1
          Intensity of the lightest color in the palette.

并且为了缩短它,仅使用第一个字母就足够了

"ch:rot=-0.2,dark=0.3"

请注意,无法通过此字符串迷你语言选择颜色的数量。