问题
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