Last active
October 10, 2021 03:57
-
-
Save drazenz/a5f4b7a183a92695328a710681cc780a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | |
| ) |
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
am getting error @ c=color.apply(value_to_color)
error : name 'color' is not defined
where we defined the color ? can you please explain am new to python