Matplotlib.axes.axes.matshow()
Matplotlib是Python中的一个库,它是NumPy库的数值-数学扩展。Axes包含了大多数图形元素:Axis、Tick、Line2D、Text、Polygon等,并设置坐标系。Axes的实例通过callbacks属性支持回调。
函数:matplotlib.axes.axes.matshow
matplotlib库的Axes模块中的Axes.matshow()函数也被用来绘制二维矩阵或数组的值作为颜色编码图像。
语法:
Axes.matshow(self, Z, **kwargs)
参数:该方法接受如下参数说明:
- z:包含要显示的矩阵。
返回如下内容:
- image:返回AxesImage
下面的例子演示了matplotlib.axes.axes.imshow()函数在matplotlib.axes中的作用:
示例1
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LogNorm
dx, dy = 0.015, 0.05
y, x = np.mgrid[slice(-4, 4 + dy, dy),
slice(-4, 4 + dx, dx)]
z = (1 - x / 3. + x ** 5 + y ** 5) * np.exp(-x ** 2 - y ** 2)
z = z[:-1, :-1]
z_min, z_max = -np.abs(z).max(),
np.abs(z).max()
fig, ax = plt.subplots()
c = ax.matshow(z, cmap ='Greens',
vmin = z_min,
vmax = z_max,
extent =[x.min(),
x.max(),
y.min(),
y.max()],
interpolation ='nearest',
origin ='lower')
fig.colorbar(c, ax = ax)
ax.set_title('matplotlib.axes.Axes.matshow() Examples\n')
plt.show()
输出:
示例2
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
def samplemat(dims):
"""Make a matrix with all zeros and increasing
elements on the diagonal"""
aa = np.zeros(dims)
for i in range(min(dims)):
aa[i, i] = np.sin(i**3)**2 + i**3
return aa
# Display matrix
fig, ax = plt.subplots()
ax.matshow(samplemat((9, 9)), cmap ="Accent")
ax.set_title('matplotlib.axes.Axes.matshow() Examples\n')
plt.show()
输出: