matplotlib顯示照片

import numpy as np
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
from matplotlib.path import Path
from matplotlib.patches import PathPatch

delta = 0.025
x = y = np.arange(-3.0, 3.0, delta)
# 生成數據-3到3每個數據間隔0.025
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2) * 2

fig, ax = plt.subplots()
m = ax.imshow(Z, interpolation='nearest', cmap=cm.RdYlGn,
               origin='lower', extent=[-3, 3, -3, 3],
               vmax=abs(Z).max(), vmin=-abs(Z).max())



# interpolation Supported values are 'none', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning',
# 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos'.
plt.show()

1、np.meshgrid(x, y) 畫個網格indexing默認爲’xy’(第一個參數做x軸,第一個參數的數組長度是這個網格的寬度。如果x的長度爲3y,y的長度爲2那麼X就是一個(23)的數組,Y就是(23)的數組))、可以選’ij’(和’xy’相反)
在這裏插入圖片描述
matplotlib.pyplot.subplots()的作用是劃分子圖
參數爲:
1、nrows 這個畫布有幾行,默認爲1。
2、ncols 這個畫布有幾列 ,默認爲1。
3、sharex 是否共享x軸,可選’none’ 不共享,‘all’ 在行和列上都共享,'row’表示只在行上共享,'col’只在列上共享,默認爲False。
4、sharey 和sharex一樣。
在這裏插入圖片描述

5、返回值爲Figure類(用來設置畫布)和asex(定位子圖的位置)下面的SupPlotBase類
subplots的官方解釋

ax.imshow()用來畫照片
參數:
1、X : 爲照片的類型是(M,N)灰色圖像、(M,N,3)三通道照片(M,N,4)四通道照片。X的取值爲(0-1 float or 0-255 int),不符合條件的自動修改。
2、cmap : 顏色圖譜,默認爲RGB(A),
在這裏插入圖片描述

3、norm : 規範數據,將標量數據規範到0-1。如果是RGB(A)的數據則自動忽略。
interpolation :默認爲 ‘nearest’。對照片進行渲染。在這裏插入圖片描述

取值爲: ‘none’, ‘nearest’, ‘bilinear’, ‘bicubic’, ‘spline16’, ‘spline36’, ‘hanning’, ‘hamming’, ‘hermite’, ‘kaiser’, ‘quadric’, ‘catrom’, ‘gaussian’, ‘bessel’, ‘mitchell’, ‘sinc’, ‘lanczos’.
3、alpha : 照片的透明度。取值範圍0-1
4、vmin, vmax : 也是用來規範化數據的,vmin是照片中最小的值,vmax是最大的值
origin : 指定原點(0,0)的位置{‘upper’, ‘lower’}upper是照片的左上角,lower是左下角
extent : 確定X,Y軸的邊界(left, right, bottom, top)
官網解釋

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章