Seaborn Diverging_palette():颜色看起来与预期不同
我正在尝试使用自定义 Diverging_palette()
创建相关矩阵的Seaborn heatmap()
。我想在极端情况下具有 100%红,中心的 100%白色。
我使用了下面的代码,但是在极端情况下粉红色,在中心浅灰色(请参阅屏幕截图)。我会说 HSL(0,100%,50%)
应该给红色吗?我想念什么?
corr_matrix = ames_train_cleaned.select_dtypes(include=[np.number]).corr()
fig, ax = plt.subplots(figsize=(15,15))
my_palette = sns.diverging_palette(h_neg=0, h_pos=0, s=100, l=50, sep=100, as_cmap=True)
_ = sns.heatmap(data=corr_matrix,
ax=ax,
mask=np.triu(corr_matrix, k=1),
cmap=my_palette,
center=0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
回答我自己的问题...我在stackoverflow上发现了这个Q& a,它指向了正确的方向。
seaborn diverdiverging_palette,用超过2个彩色音调
取代
my_palette
的定义在我的代码snippet中使用:my_palette = linearsememensemensegendeDcolorMap.from_list(name ='dummy',colors = ['blue','white','white','red''])< /code>
这很好,但是我仍然不确定为什么在我的初始解决方案中 red 不是 red ...
Answering my own question... I found this Q&A on StackOverflow which pointed me in the right direction.
Seaborn diverging_palette with more than 2 color tones
Replaced the definition of
my_palette
in my code-snippet with this:my_palette = LinearSegmentedColormap.from_list(name='dummy', colors=['blue','white','red'])
This works perfectly, but I'm still not sure why the red wasn't red in my initial solution...
您期望
sns.diverging_palette
在HSL Colorspace中运行,但实际上它在HUSL中运行,现在被称为 hsluv 。当前的文档正确地表明了这一点,但是如果您以前从未见过HUSL,可能会令人困惑。这是计算器向您展示HUSL色轮。不幸的是,您正在寻找的纯蓝色/红色在此色轮上具有不同的亮度值,因此您无法通过当前实现来实现所需的确切映射。从您的自我答案中蓝色/白/红色的紧密近似是
sns.diverging_palette(266、12、100、32,n = 256,as_cmap = true,center =“ light”)
<) < < a href =“ https://i.sstatic.net/j7vvop2c.png” rel =“ nofollow noreferrer”>
You're expecting
sns.diverging_palette
to operate in the HSL colorspace, but it actually operates in HUSL which is now known as HSLuv. The current docs correctly indicate this, but it can be confusing if you've never seen HUSL before.Here's a calculator to show you the HUSL color wheel. Unfortunately the pure blue/red you're looking for have different luminance values on this color wheel, so you can't achieve the exact map you're looking for with the current implementation. A close approximation of the blue/white/red from your self-answer is
sns.diverging_palette(266, 12, 100, 32, n=256, as_cmap=True, center="light")