0

I have a matrix , and I used sns for visualizing it, However , what I wish is : if the value is anything less than 0, it should be blue, if its in range of 0.0-0.99 it should be grey and anything above 1, should be pink,

I tried as mentioned, but i am not sure how to tackle negative values, I followed this : How to set fixed color ranges with Seaborn heatmap?

and the code that I generally used is:

plt.figure(figsize = (16,16))
sns.heatmap(p, annot=True, square=True)

enter image description here

Can anyone please suggest, how can I achieve this? Thank you in advance.

Coder
  • 67
  • 7
  • 1
    Try this: `uniform_data = np.array([np.random.uniform(-2, 2) for i in range(120)]); uniform_data = uniform_data.reshape(10, 12); my_colors = ['blue', 'gray', 'pink']; my_cmap = ListedColormap(my_colors); bounds = [-2, 0.0, 0.99, 2]; my_norm = BoundaryNorm(bounds, ncolors=len(my_colors)); ax = sns.heatmap(uniform_data, annot=True, square=True, cmap=my_cmap, norm=my_norm)` – r-beginners Oct 06 '22 at 07:44
  • Why are negative numbers harder? You can use the `min` and `max` values of your matrix as extra boundaries – Josh Friedlander Oct 06 '22 at 07:54

0 Answers0