Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。軸類包含大多數圖形元素:Axis,Tick,Line2D,Text,Polygon等,並設置坐標係。 Axes實例通過callbacks屬性支持回調。
matplotlib.axes.Axes.matshow()函數
matplotlib庫的axiss模塊中的Axes.matshow()函數還用於將2D矩陣或數組的值繪製為color-coded圖像。
用法:
Axes.matshow(self, Z, **kwargs)
參數:此方法接受以下描述的參數:
- z:此參數包含要顯示的矩陣。
返回值:這將返回以下內容:
- 圖片:這將返回AxesImage
以下示例說明了matplotlib.axes中的matplotlib.axes.Axes.imshow()函數:
示例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()
輸出:
相關用法
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Matplotlib.axes.Axes.matshow() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。