I have a dataset with values -4 to 4 and some nan values. I plot the heatmap using seaborn heatmap. Colormap I need to use is from red to white to blue. My problem is masked cells are also white/greyish which is hard to differentiate then values close to 0 in colormap.
Is there any way to assign nan values as black without plotting the heatmap twice?
You have two options.
Use the bad
value of the colormap. I.e. if masked values are set to nan
, they would be shown in the color set to the colormap via
colormap.set_bad("black")
Make the background of the axes black, such that values which are masked and hence not plotted appear as transparent with the background color see through,
ax.set_facecolor("black")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With