How to pass RGBA color into Seaborn PairGrid

安稳与你 提交于 2021-02-05 09:28:05

问题


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)

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?


回答1:


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.

change to: 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)



来源:https://stackoverflow.com/questions/65374750/how-to-pass-rgba-color-into-seaborn-pairgrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!