基于matplotlib的数据可视化 - 热图imshow
熱圖:
Display an image on the axes.?
可以用來(lái)比較兩個(gè)矩陣的相似程度
mp.imshow(z, cmap=顏色映射,origin=垂直軸向)
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 -?array_like, shape (n, m) or (n, m, 3) or (n, m, 4);Display the image in `X` to current axes.
? ? ?X 可以是數(shù)組array,或PIL image,若為數(shù)組,它following shapes and types
? ? - M * N -- values to be mapped (float or int);該數(shù)組形式基于norm(將標(biāo)量映射到標(biāo)量 mapping scalar to scalar)和 cmap(將標(biāo)準(zhǔn)標(biāo)量映射到顏色mapping the normed scalar to a color)
? ? - M * N * 3 -- RGB (float or uint8)
? ? - M * N * 4 -- RGBA (float or uint8)
RGB和RGBA陣列的元素表示M * N圖像的像素。 對(duì)于浮點(diǎn)數(shù),所有值應(yīng)在[0 .. 1]的范圍內(nèi),對(duì)于整數(shù),所有值應(yīng)在[0 ... 255]的范圍內(nèi)。 超出范圍的值將被剪切到這些邊界。
cmap -?optional, default: None
aspect - ['auto' | 'equal' | scalar], optional, default: None
? ? auto -?則更改圖像寬高比以匹配軸的寬高比。
? ? equal -?If 'equal', and `extent` is None,?則更改軸縱橫比以匹配圖像的縱橫比。 If `extent` is not `None`, 則更改軸縱橫比以匹配范圍。
interpolation - string, optional, default: None ,?
? ? ?Acceptable values are 'none', 'nearest', 'bilinear', 'bicubic',?'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser',?'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc',
'lanczos'
norm -??: `~matplotlib.colors.Normalize`, optional, default: None 略
vmin, vmax - scalar, optional, default: None
? ??`vmin`和`vmax`與norm結(jié)合使用以標(biāo)準(zhǔn)化亮度數(shù)據(jù)。 注意,如果傳遞一個(gè)`norm`實(shí)例則`vmin`和`vmax`的設(shè)置將被忽略。
alpha - scalar, optional, default: None
? ??介于0(透明)和1(不透明)之間。RGBA input data 時(shí) alpha 參數(shù)自動(dòng)忽略
origin : ['upper' | 'lower'], optional, default: None
? ??將數(shù)組的[0,0]索引放在軸的左上角( upper) 或左下角( lower) 。 如果為None,則默認(rèn)為rc`mage.origin`。
extent : scalars (left, right, bottom, top), optional, default: None
? ??數(shù)據(jù)坐標(biāo)中左下角和右上角的位置。 如果為“無(wú)”,則定位圖像使得像素中心落在基于零的(行,列)索引上。
shape : scalars (columns, rows), optional, default: None
? ? For raw buffer images
filternorm - scalar, optional, default: 1
filterrad?- scalar, optional, default: 4.0
示例
import numpy as np import matplotlib.pyplot as pltn = 1000 # 用meshgrid生成一個(gè)二維數(shù)組 x, y = np.meshgrid(np.linspace(-3, 3, n), np.linspace(-3, 3, n)) z = (1 - x / 2 + x**5 + y**3) * np.exp(-x**2 - y**2)# 畫(huà)圖 plt.figure('Hot', facecolor='lightgray') plt.title('hotshot', fontsize=20) plt.xlabel('x', fontsize=14) plt.ylabel('y', fontsize=14) plt.tick_params(labelsize=10) plt.grid(linestyle=':')plt.imshow(z, cmap='jet', origin='low') plt.colorbar().set_label('z', fontsize=14)plt.show()?
?官方網(wǎng)站?Image tutorial?、
Matplotlib調(diào)用imshow()函數(shù)繪制熱圖
matplotlib熱圖
??
?
總結(jié)
以上是生活随笔為你收集整理的基于matplotlib的数据可视化 - 热图imshow的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【Linux】cp命令
- 下一篇: POJ 3259 Wormholes【最