基于matplotlib的数据可视化 - 热图imshow
熱圖:
Display an image on the axes.?
可以用來比較兩個矩陣的相似程度
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(將標量映射到標量 mapping scalar to scalar)和 cmap(將標準標量映射到顏色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圖像的像素。 對于浮點數(shù),所有值應在[0 .. 1]的范圍內,對于整數(shù),所有值應在[0 ... 255]的范圍內。 超出范圍的值將被剪切到這些邊界。
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結合使用以標準化亮度數(shù)據(jù)。 注意,如果傳遞一個`norm`實例則`vmin`和`vmax`的設置將被忽略。
alpha - scalar, optional, default: None
? ??介于0(透明)和1(不透明)之間。RGBA input data 時 alpha 參數(shù)自動忽略
origin : ['upper' | 'lower'], optional, default: None
? ??將數(shù)組的[0,0]索引放在軸的左上角( upper) 或左下角( lower) 。 如果為None,則默認為rc`mage.origin`。
extent : scalars (left, right, bottom, top), optional, default: None
? ??數(shù)據(jù)坐標中左下角和右上角的位置。 如果為“無”,則定位圖像使得像素中心落在基于零的(行,列)索引上。
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生成一個二維數(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)# 畫圖 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()?
?官方網站?Image tutorial?、
Matplotlib調用imshow()函數(shù)繪制熱圖
matplotlib熱圖
??
?
總結
以上是生活随笔為你收集整理的基于matplotlib的数据可视化 - 热图imshow的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Linux】cp命令
- 下一篇: Vue源码解析之AST语法树(三)