-1

I have two heatmaps I've made in python. I use seaborn for both of them, but I'm not wedded to it.

Both these heatmaps are on the same 20x20 grid. One of the heatmaps is a background, dividing the 20x20 grid into 3 large regions. The other heatmap shows a hotspot, a smaller box that is lit up, and then the rest of the background is zero.

I would like to superimpose the heatmap with the hotspot in front of the background heatmap. I haven't found anything remotely helpful. Does anyone know of a good way to do this? I haven't found how to do this in seaborn.

Here is my sample code, where background is one of the arrays and hotspot is the other array.

sns.heatmap(background)
sns.heatmap(hotspot, cmap='RdBu_r')
plt.show()

But this just shows the heatmap for hotspot. I would like the heatmap for hotspot superimposed on the background.

1 Answers1

1

heatmap is an Axes-level function and therefore you can just give it an axes as an argument.

_, ax = plt.subplots()

sns.heatmap(background, ax=ax)
sns.heatmap(hotspot, cmap='RdBu_r', ax=ax)
plt.show()
Josh Friedlander
  • 10,870
  • 5
  • 35
  • 75
  • 1
    You probably need to convert the zeros of `hotspot` to `NaN`s to prevent erasing the background. – JohanC Oct 18 '22 at 17:23