Skip to content

Instantly share code, notes, and snippets.

@drazenz
Last active October 10, 2021 03:57
Show Gist options
  • Select an option

  • Save drazenz/a5f4b7a183a92695328a710681cc780a to your computer and use it in GitHub Desktop.

Select an option

Save drazenz/a5f4b7a183a92695328a710681cc780a to your computer and use it in GitHub Desktop.
n_colors = 256 # Use 256 colors for the diverging color palette
palette = sns.diverging_palette(20, 220, n=n_colors) # Create the palette
color_min, color_max = [-1, 1] # Range of values that will be mapped to the palette, i.e. min and max possible correlation
def value_to_color(val):
val_position = float((val - color_min)) / (color_max - color_min) # position of value in the input range, relative to the length of the input range
ind = int(val_position * (n_colors - 1)) # target index in the color palette
return palette[ind]
ax.scatter(
x=x.map(x_to_num),
y=y.map(y_to_num),
s=size * size_scale,
c=color.apply(value_to_color), # Vector of square color values, mapped to color palette
marker='s'
)
@werhu
Copy link

werhu commented Feb 11, 2020

You can replace color with corr['value'] since this is the DataSeries we want to apply the colors to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment