python 带注释的热图

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 带注释的热图相关的知识,希望对你有一定的参考价值。

# hist2d returns a number of different variables, including an array of counts
bins_x = np.arange(0.5, 10.5+1, 1)
bins_y = np.arange(-0.5, 10.5+1, 1)
h2d = plt.hist2d(data = df, x = 'disc_var1', y = 'disc_var2',
               bins = [bins_x, bins_y], cmap = 'viridis_r', cmin = 0.5)
counts = h2d[0]

# loop through the cell counts and add text annotations for each
for i in range(counts.shape[0]):
    for j in range(counts.shape[1]):
        c = counts[i,j]
        if c >= 7: # increase visibility on darkest cells
            plt.text(bins_x[i]+0.5, bins_y[j]+0.5, int(c),
                     ha = 'center', va = 'center', color = 'white')
        elif c > 0:
            plt.text(bins_x[i]+0.5, bins_y[j]+0.5, int(c),
                     ha = 'center', va = 'center', color = 'black')

以上是关于python 带注释的热图的主要内容,如果未能解决你的问题,请参考以下文章

带注释的热图轴顺序取决于数据类型

Plotly:当 scaleanchor = x 时,如何调整带注释的热图的轴标签?

Plotly:如何在带注释的热图中舍入显示文本但在悬停时保持完整格式?

绘制聚类热图(带树状图)/Python

自定义注释 Seaborn 热图

为啥用 Plotly 显示热图时会出现这个问题?