I have some data that I'm visualizing in two different ways. The first is using seaborn.heatmap and the second using seaborn.kdeplot. What I would like is to use the color of each cell in the heatmap to color the corresponding kdeplot. Example:
this_matrix = np.random.normal(0,1,size=(100,100))
seaborn.heatmap(this_matrix)
What I would like is to return the color (rgb tuple) that is used in each cell of the above heatmap by seaborn.
CodePudding user response:
You can just do what seaborn does:
import matplotlib.colors as mcolors
import numpy as np
import matplotlib.cm as cm
data = np.random.randn(5, 5)
norm = mcolors.Normalize()
data_normed = norm(data)
data_rgba = cm.viridis(data_normed)
Note that if you use a different colormap, you should change viridis
and if you specify the vmin
and vmax
, you should pass those as arguments to Normalize