python绘制excel数据热力图
1.首先安装PIP
2.安装插件 xlrd numpy matplotlib(不多做描述)
大体思路就是 通过xlrd读取excel的数据,默认存放在list当中,再将list数组转换为python矩阵。通过二维图形显示出来
from numpy import *
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import xlrd
from matplotlib.colors import LogNorm
import numpy as np
data = xlrd.open_workbook('d:\\jianmo\\A2.xls')
table = data.sheets()[4]
nrows = table.nrows
ncols = table.ncols
c1=arange(0,nrows,1)
datamatrix=zeros((nrows,ncols))
for x in range(ncols):
cols =table.col_values(x)
minVals=min(cols)
maxVals=max(cols)
cols1=matrix(cols)
ranges=maxVals-minVals
b=cols1-minVals
normcols=b/ranges
datamatrix[:,x]=normcols
x, y =(0,800),(0,500)
plt.imshow(datamatrix+10, extent=(np.amin(x), np.amax(x), np.amin(y), np.amax(y)),
cmap=cm.hot, norm=LogNorm())
plt.colorbar()
plt.show()
转载自:https://blog.csdn.net/kansas_lh/article/details/78007554