matplotlib.pyplot.matshow 矩陣可視化實(shí)例
這是一個(gè)繪制矩陣的函數(shù)。
用matshow繪制矩陣的例子:
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] = i return aa # Display matrix plt.matshow(samplemat((15, 15))) plt.show()
效果圖:

補(bǔ)充知識(shí):利用matplotlib將矩陣畫成三維圖
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits import mplot3d
cap = cv.VideoCapture(0)
cpframe = None
while True:
ret, frame = cap.read()
cv.imshow("video", frame)
if cv.waitKey(1) & 0xFF ==ord('q'):
cpframe = frame
break
img_gray = cv.cvtColor(cpframe, cv.COLOR_RGB2GRAY)
Y = np.arange(0, np.shape(img_gray)[0], 1)
X = np.arange(0, np.shape(img_gray)[1], 1)
X, Y = np.meshgrid(X, Y)
fig = plt.figure()
ax = plt.axes(projection="3d")
ax.plot_surface(X, Y, img_gray, cmap=cm.gist_rainbow)
plt.show()

以上這篇matplotlib.pyplot.matshow 矩陣可視化實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
python解決12306登錄驗(yàn)證碼的實(shí)現(xiàn)
這篇文章主要介紹了python解決12306登錄驗(yàn)證碼的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04
淺談django model postgres的json字段編碼問題
下面小編就為大家分享一篇淺談django model postgres的json字段編碼問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-01-01
用openCV和Python 實(shí)現(xiàn)圖片對(duì)比,并標(biāo)識(shí)出不同點(diǎn)的方式
今天小編就為大家分享一篇用openCV和Python 實(shí)現(xiàn)圖片對(duì)比,并標(biāo)識(shí)出不同點(diǎn)的方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-12-12
Python?pycharm讀取文件相對(duì)路徑與絕對(duì)路徑的方法
這篇文章主要給大家介紹了關(guān)于Python?pycharm讀取文件相對(duì)路徑與絕對(duì)路徑的方法,絕對(duì)路徑就是文件的真正存在的路徑,是指從硬盤的根目錄(盤符)開始,進(jìn)行一級(jí)級(jí)目錄指向文件,相對(duì)路徑就是以當(dāng)前文件為基準(zhǔn)進(jìn)行一級(jí)級(jí)目錄指向被引用的資源文件,需要的朋友可以參考下2023-12-12
OpenCV-Python實(shí)現(xiàn)圖像平滑處理操作
圖像平滑處理的噪聲取值主要有6種方法,本文主要介紹了這6種方法的具體使用并配置實(shí)例方法,具有一定的參考價(jià)值,感興趣的可以了解一下2021-06-06

