1. ? ? 使用plt.imshow函數(shù)繪制熱力圖
imshow(X, cmap=None,norm=None, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None,origin=None, extent=None, shape=None, filternorm=1, filterrad=4.0, imlim=None,resample=None, url=None, hold=None, data=None, **kwargs)
X為數(shù)組贰谣,數(shù)組矩陣重構(gòu)队橙,可使用reshape函數(shù)
2. ? ?用第三方庫seaborn.heatmap繪制熱力圖
seaborn.heatmap(data,vmin=None, vmax=None, cmap=None, center=None, robust=False, annot=None,fmt='.2g', annotkws=None, linewidths=0, linecolor='white', cbar=True,cbarkws=None, cbar_ax=None, square=False, ax=None, xticklabels=True,yticklabels=True, mask=None, **kwargs)
3. ? ?mshow()與seeborn.heatmap的區(qū)別
a、 seeborn.heatmap能直接把顏色調(diào)出來,cbar=False取消顏色棒的顯示贬芥,默認(rèn)為True
plt.imshow()需要另外調(diào)用一個(gè)函數(shù)plt.colorbar()。其中plt.colorbar() 參數(shù)shrink的值為bar的壓縮尺寸蜀备,默認(rèn)為1
b删咱、 seaborn.heatmap能在圖表顯示數(shù)據(jù),參數(shù)annot=True
4. ? ? 用標(biāo)簽替代坐標(biāo)值的方法
a奶赔、使用figure
? ?plt.yticks(range(len(ylabel)), ylabel)
??? plt.xticks(range(len(xlabel)), xlabel)
b惋嚎、使用figure顯式創(chuàng)建Axes
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111, position=[0.1, 0.15, 0.8, 0.8])
ax.set_yticks(range(len(ylabel)))
ax.set_yticklabels(ylabel)? #用ylabel替代y坐標(biāo)值
ax.set_xticks(range(len(xlabel)))
ax.set_xticklabels(xlabel)
5. ? ?顏色設(shè)置
interpolation的設(shè)定,取‘nearest’站刑,默認(rèn)‘None’另伍;vmax/vmin取數(shù)組的最大最小;extend包含坐標(biāo)軸的四個(gè)角值摆尝,xmin/xmax温艇、ymin/ymax
6. ? ? reshape函數(shù)的使用
reshape函數(shù)總是將原矩陣A,重組為新矩陣B堕汞,這里A勺爱、B元素個(gè)數(shù)需相同。重組的規(guī)則如下:
總是先處理低維的讯检,再處理高維的琐鲁,比如要把4*6的A變?yōu)?*4的B,就要先掃描A的第一列人灼,掃描過程中行數(shù)不斷發(fā)生變化围段,列數(shù)隔一段時(shí)間變化一次,這就是前面說的:先處理低維再處理高維(行是低維投放,列比行高一維)
7. ? ? random包含的函數(shù)
rand奈泪、randn、seed灸芳、choice段磨、random、randint耗绿、uniform