创建热图图时,cmap规范化不会更新

时间:2018-08-17 16:15:26

标签: python-3.x colors heatmap boundary

我正在尝试创建一个二进制热图,用户将在其中输入一个阈值,并且两种颜色将在该阈值之上和之下变化。下面的代码最初会起作用,但是如果您更改阈值,则图不会更新。

import panadas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns    

hm = pd.DataFrame([[0,0,0.1,0.1,0.2,0.6,0.9],[0,0,0.1,0.2,0.3,0.7,1],[0.1,0.2,0.1,0.3,0.4,0.8,1]])

#User input
threshold = 0.3

# define the colors and create a normalize object the describes the limits of each color
cmap = mpl.colors.ListedColormap(['r', 'k'])
bounds = [0., threshold, 1.]
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)

# plot and save binary heatmap
sns.heatmap(hm,cmap=cmap,cbar_kws={'pad':0.15,"orientation": "horizontal",'label': 'Predicted Probability'}) 
plt.xlabel('Gordana Score')
plt.title('%s_Score Heatmap' %filename)
plt.show()

0 个答案:

没有答案