matplotlib绘制热力图 主要是有两种方式 需要矩阵形式的数据,热力图用颜色的山前表示数据对应位置的大小 第一种方式matplotlib.pyplot.imshow() imshow()主要是用于在坐标轴上展示图片,所以可以用来绘制热力图 用法
matplotlib.pyplot.imshow(X, cmap=None, norm=None, *, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None, origin=None, extent=None, interpolation_stage=None, filternorm=True, filterrad=4.0, resample=None, url=None, data=None, **kwargs)
这里参数就不全部介绍了,因为不是主要绘制热力图的, 介绍下cmap这个参数 官方网址
-
统一的序列颜色映射,(中间对应的颜色值命名)  -
顺序颜色序列(以色系名称命名,由低饱和度到高过度)  第二种是以二进制颜色代码命名,这个需要查下  -
发散的颜色 向两端发散  -
离散化的色系  -
不均一的颜色系列  案例
import numpy as np
import matplotlib.pyplot as plt
x = np.random.rand(100).reshape(10,10)
plt.imshow(x, cmap=plt.cm.hot, vmin=0, vmax=1)
plt.colorbar()
plt.show()

离散化色系演示
import numpy as np
import matplotlib.pyplot as plt
x = np.random.rand(100).reshape(10,10)
plt.imshow(x, cmap=plt.cm.Set3, vmin=0, vmax=1)
plt.colorbar()
plt.show()
 
第二种方法,matplotlib.pyplot.matshow()
import numpy as np
import matplotlib.pyplot as plt
x = np.random.rand(10, 10)
plt.matshow(x, cmap = plt.cm.winter, vmin=0, vmax=1)
plt.colorbar()
plt.show()

|