python绘制heatmap

import numpy as np
import matplotlib.pyplot as plt

data = np.array([791643, 63, 1250, 84, 96, 44, 52, 552, 84, 146,
                 64, 1053254, 53, 146, 107, 43, 46, 97, 103, 64,
                 1212, 56, 790742, 100, 70, 96, 61, 1070, 115, 303,
                 86, 136, 91, 1150511, 1212, 79, 44, 178, 95, 103,
                 93, 117, 87, 1285, 1259635, 86, 48, 66, 353, 71,
                 44, 51, 77, 97, 98, 1087581, 38, 60, 463, 43,
                 66, 39, 54, 44, 51, 35, 590175, 85, 55, 77,
                 522, 86, 945, 173, 59, 49, 71, 876629, 204, 154,
                 81, 118, 90, 94, 375, 461, 41, 172, 1231624, 80,
                 155, 77, 282, 100, 66, 41, 83, 189, 81, 1033678]).reshape(10, 10)
# print(len(data))      #len(data) 返回的是data的行数
# print(len(data[1]))   #len(data[1]) 返回的是data的列数
# print(data.shape)
# 创建一个图形窗口
plt.figure(figsize=(12, 9))

# 使用imshow绘制热力图
heatmap = plt.imshow(data, cmap='Blues')

# 添加数值标签
for i in range(len(data)):
    for j in range(len(data[0])):
        plt.text(j, i, str(data[i, j]), ha='center', va='center', fontsize=10, color='red')

# 添加颜色条
plt.colorbar(heatmap)

# 自定义x轴和y轴的标签
x_labels = ['D01','D02','D03','D04','D05','D06','D07','D08','D09','D10']
y_labels = ['D01','D02','D03','D04','D05','D06','D07','D08','D09','D10']

# 设置自定义的x轴和y轴标签
plt.xticks(np.arange(len(x_labels)), x_labels, rotation=45)
plt.yticks(np.arange(len(y_labels)), y_labels)

plt.savefig('new_heatmap.png', dpi = 2400)#保存图片

效果展示
python绘制heatmap_第1张图片

你可能感兴趣的:(python,开发语言)