I'm trying to put a heatmap over an image I have using seaborn and matplotlib, but the output doesn't show anything. I looked at the first answer of:
Plotting seaborn heatmap on top of a background picture
I took nearly the exact same code and nothing is showing I don't know why.
import matplotlib.image as mpimg
import matplotlib.cm
import seaborn as sns
import matplotlib.pyplot as plt
wd = matplotlib.cm.winter._segmentdata # only has r,g,b
wd['alpha'] = ((0.0, 0.0, 0.3),
(0.3, 0.3, 1.0),
(1.0, 1.0, 1.0))
al_winter = matplotlib.colors.LinearSegmentedColormap('AlphaWinter', wd)
map_img = mpimg.imread('./my_picture.png')
hmax = sns.heatmap(results,
cmap = al_winter, # this worked but I didn't like it
#cmap = matplotlib.cm.winter,
alpha = 0.5, # whole heatmap is translucent
annot = True,
zorder = 2
)
# The heatmap is working as I can see the output in my notebook.
hmax.imshow(map_img,
aspect = hmax.get_aspect(),
extent = hmax.get_xlim() + hmax.get_ylim(),
zorder = 1) #put the map under the heatmap
plt.show()
# Here the output is empty.
The last output is empty and I don't know why, I tried to do hmax.imshow(map_img)
and nothing is showing too except <matplotlib.image.AxesImage at 0x129888670>
. Is this normal? I'm not sure if the problem comes from my picture, heatmap, or code.