如何将RGBA颜色传递给Seaborn PairGrid [英] How to pass RGBA color into Seaborn PairGrid
问题描述
我定义了一个 PairGrid 函数,效果很好
I have defined a PairGrid function, which works fine
grid = sns.PairGrid(data= df,
vars = ['sugarpercent', 'pricepercent', 'winpercent'], size = 3)
# Map the plots to the locations
grid = grid.map_upper(plt.scatter, color = 'darkred')
grid = grid.map_upper(corr)
grid = grid.map_upper(sns.regplot, line_kws={'color': 'darkred'}, lowess=True)
但是,对于 scatter 和 regplot 函数,我想使用 RGBA (12, 50, 196, 0.6)
而不是深红色.我试图替换元组'color':(12,50,196,0.6)
,并收到以下错误: ValueError:RGBA值应在0-1范围内
.读了一点,似乎我需要迭代并将颜色分配给每个数据点.那是对的吗?当绘图函数作为参数传递时,你如何做到这一点?
However, I want to use RGBA (12, 50, 196, 0.6)
instead of darkred for both scatter and regplot function. I tried to replace the tuple 'color': (12, 50, 196, 0.6)
, and got this error: ValueError: RGBA values should be within 0-1 range
.
Having read a bit, it seems that I need to iterate over and assign the color to each data point. Is that correct? How do you do that when the plotting function is passed as a parameter?
推荐答案
该错误不言自明.RGB(A) 值需要在 0-1 之间,而您的值 (12, 50, 196)
(最有可能)在 0-255 之间.
The error is pretty self-explanatory. RGB(A) values need to be between 0–1, while your values (12, 50, 196)
are (most likely) between 0–255.
改为:color=(12/255, 50/255, 196/255, 0.6)
my_color = (12/255, 50/255, 196/255, 0.6)
g = sns.PairGrid(penguins)
g.map_upper(plt.scatter, color=my_color)
g.map_upper(sns.regplot, line_kws={'color': my_color}, lowess=True)
这篇关于如何将RGBA颜色传递给Seaborn PairGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!