python 热力图heatmap

python的热力图是用皮尔逊相关系数来查看两者之间的关联性

#encoding:utf-8
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from matplotlib import cm
from matplotlib import axes
import pylab
pylab.mpl.rcParams['font.sans-serif'] = ['SimHei']#防止中文乱码
pylab.mpl.rcParams['axes.unicode_minus'] = False#防止中文乱码
def draw_heatmap(data,xlabels,ylabels):
    cmap = cm.Blues
    figure=plt.figure(facecolor='w')
    ax=figure.add_subplot(2,1,1,position=[0.1,0.15,0.8,0.8])
    ax.set_yticks(range(len(ylabels)))
    ax.set_yticklabels(ylabels)
    ax.set_xticks(range(len(xlabels)))
    ax.set_xticklabels(xlabels)
    vmax=data[0][0]
    vmin=data[0][0]
    for i in data:
        for j in i:
            if j>vmax:
                vmax=j
            if j

结果:

python 热力图heatmap_第1张图片

 

你可能感兴趣的:(python)