温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何在python中使用heatmap绘制热力图

发布时间:2021-04-30 15:50:43 来源:亿速云 阅读:370 作者:Leah 栏目:开发技术

如何在python中使用heatmap绘制热力图?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

python的五大特点是什么

python的五大特点:1.简单易学,开发程序时,专注的是解决问题,而不是搞明白语言本身。2.面向对象,与其他主要的语言如C++和Java相比, Python以一种非常强大又简单的方式实现面向对象编程。3.可移植性,Python程序无需修改就可以在各种平台上运行。4.解释性,Python语言写的程序不需要编译成二进制代码,可以直接从源代码运行程序。5.开源,Python是 FLOSS(自由/开放源码软件)之一。

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<vmin:
    vmin=j
 map=ax.imshow(data,interpolation='nearest',cmap=cmap,aspect='auto',vmin=vmin,vmax=vmax)
 cb = plt.colorbar(mappable=map,cax=None,ax=None,shrink=0.5)
 plt.xticks(rotation=90) # 将字体进行旋转
 plt.yticks(rotation=360)
 plt.show()
data = pd.read_csv('test.csv',encoding='gbk')
a = [[1063620,291288,213322,120233,972752,1896180,483012,1609664,413538,778350,420643,212472,2599510,1574470,254141],[258914,48064,31948,19534,142792,295841,69143,291524,78926,90238,79336,47938,454656,271486,35304],[517687,135483,68418,66670,301544,777798,307562,810314,234086,238859,145959,125258,1480672,764612,153237],[277377,38581,31145,17612,121162,254534,60746,253148,62054,93499,63346,36422,356036,212109,27758],[19030,2835,2174,1575,7325,18258,6837,23457,5340,5277,5120,4017,34122,21314,2961],[351720,107299,57186,55485,337368,563436,188368,563515,128047,178664,117886,72451,798121,444825,65599]]
 
 
xlabels= [u'3C电子',u'房产家居',u'服饰',u'健康保健',u'金融财经',u'旅游',u'美容美体',u'汽车',u'求职&教育',u'奢侈品',u'体育健身',u'网游',u'休闲&爱好',u'影视娱乐',u'孕婴育儿']
ylabels= ['iphoneX','mix2','oppor11','samsang','vivo','mate10']
draw_heatmap(a,xlabels,ylabels)

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI