
- Matplotlib 基礎
- Matplotlib - 首頁
- Matplotlib - 簡介
- Matplotlib - 與 Seaborn 的比較
- Matplotlib - 環境搭建
- Matplotlib - Anaconda 發行版
- Matplotlib - Jupyter Notebook
- Matplotlib - Pyplot API
- Matplotlib - 簡單繪圖
- Matplotlib - 儲存圖表
- Matplotlib - 標記
- Matplotlib - 圖表
- Matplotlib - 樣式
- Matplotlib - 圖例
- Matplotlib - 顏色
- Matplotlib - 顏色圖
- Matplotlib - 顏色圖歸一化
- Matplotlib - 選擇顏色圖
- Matplotlib - 顏色條
- Matplotlib - 文字
- Matplotlib - 文字屬性
- Matplotlib - 子圖示題
- Matplotlib - 圖片
- Matplotlib - 圖片蒙版
- Matplotlib - 註釋
- Matplotlib - 箭頭
- Matplotlib - 字型
- Matplotlib - 什麼是字型?
- 全域性設定字型屬性
- Matplotlib - 字型索引
- Matplotlib - 字型屬性
- Matplotlib - 比例尺
- Matplotlib - 線性和對數比例尺
- Matplotlib - 對稱對數和 Logit 比例尺
- Matplotlib - LaTeX
- Matplotlib - 什麼是 LaTeX?
- Matplotlib - 用於數學表示式的 LaTeX
- Matplotlib - 註釋中的 LaTeX 文字格式
- Matplotlib - PostScript
- 在註釋中啟用 LaTeX 渲染
- Matplotlib - 數學表示式
- Matplotlib - 動畫
- Matplotlib - 圖形元素
- Matplotlib - 使用 Cycler 進行樣式設定
- Matplotlib - 路徑
- Matplotlib - 路徑效果
- Matplotlib - 座標變換
- Matplotlib - 刻度和刻度標籤
- Matplotlib - 弧度刻度
- Matplotlib - 日期刻度
- Matplotlib - 刻度格式化器
- Matplotlib - 刻度定位器
- Matplotlib - 基本單位
- Matplotlib - 自動縮放
- Matplotlib - 反轉座標軸
- Matplotlib - 對數座標軸
- Matplotlib - Symlog
- Matplotlib - 單位處理
- Matplotlib - 帶單位的橢圓
- Matplotlib - 脊柱
- Matplotlib - 座標軸範圍
- Matplotlib - 座標軸比例尺
- Matplotlib - 座標軸刻度
- Matplotlib - 座標軸格式化
- Matplotlib - Axes 類
- Matplotlib - 雙座標軸
- Matplotlib - Figure 類
- Matplotlib - 多圖
- Matplotlib - 網格
- Matplotlib - 面向物件介面
- Matplotlib - PyLab 模組
- Matplotlib - subplots() 函式
- Matplotlib - subplot2grid() 函式
- Matplotlib - 固定位置的圖形元素
- Matplotlib - 手動等值線
- Matplotlib - 座標報告
- Matplotlib - AGG 過濾器
- Matplotlib - 帶狀盒
- Matplotlib - 填充螺旋線
- Matplotlib - findobj 演示
- Matplotlib - 超連結
- Matplotlib - 圖片縮圖
- Matplotlib - 使用關鍵字繪圖
- Matplotlib - 建立 Logo
- Matplotlib - 多頁 PDF
- Matplotlib - 多程序
- Matplotlib - 列印標準輸出
- Matplotlib - 複合路徑
- Matplotlib - Sankey 類
- Matplotlib - MRI 與 EEG
- Matplotlib - 樣式表
- Matplotlib - 背景顏色
- Matplotlib - Basemap
- Matplotlib 事件處理
- Matplotlib - 事件處理
- Matplotlib - 關閉事件
- Matplotlib - 滑鼠移動
- Matplotlib - 點選事件
- Matplotlib - 滾動事件
- Matplotlib - 按鍵事件
- Matplotlib - 選擇事件
- Matplotlib - 透鏡
- Matplotlib - 路徑編輯器
- Matplotlib - 多邊形編輯器
- Matplotlib - 定時器
- Matplotlib - viewlims
- Matplotlib - 縮放視窗
- Matplotlib 小部件
- Matplotlib - 游標小部件
- Matplotlib - 帶註釋的游標
- Matplotlib - 按鈕小部件
- Matplotlib - 複選框
- Matplotlib - 套索選擇器
- Matplotlib - 選單小部件
- Matplotlib - 滑鼠游標
- Matplotlib - 多游標
- Matplotlib - 多邊形選擇器
- Matplotlib - 單選按鈕
- Matplotlib - RangeSlider
- Matplotlib - 矩形選擇器
- Matplotlib - 橢圓選擇器
- Matplotlib - 滑塊小部件
- Matplotlib - Span Selector
- Matplotlib - 文字框
- Matplotlib 繪圖
- Matplotlib - 條形圖
- Matplotlib - 直方圖
- Matplotlib - 餅圖
- Matplotlib - 散點圖
- Matplotlib - 箱線圖
- Matplotlib - 小提琴圖
- Matplotlib - 等高線圖
- Matplotlib - 3D 繪圖
- Matplotlib - 3D 等高線
- Matplotlib - 3D 線框圖
- Matplotlib - 3D 表面圖
- Matplotlib - 矢羽圖
- Matplotlib 有用資源
- Matplotlib - 快速指南
- Matplotlib - 有用資源
- Matplotlib - 討論
Matplotlib - 圖片
Matplotlib 中的圖片是什麼?
在 Matplotlib 庫中,顯示和操作圖片涉及使用imshow()函式。此函式視覺化二維陣列或圖片。此函式對於顯示各種格式的圖片特別有用,例如表示畫素值的陣列或實際的圖片檔案。
Matplotlib 中的圖片提供了一種視覺化網格資料的方法,方便解釋和分析以二維陣列表示的資訊。此功能對於處理影像資料的各種科學、工程和機器學習應用至關重要。
Matplotlib 中圖片的用例
以下是 Matplotlib 庫中圖片的用例。
視覺化網格資料
matplotlib 庫可用於顯示科學資料,例如熱圖、地形圖、衛星影像等。
影像處理
在計算機視覺或影像識別等應用中分析和操作影像資料。
人工智慧和機器學習
在模型的訓練和評估中處理和處理影像資料。
載入和顯示圖片
要使用 Matplotlib 庫載入和顯示圖片,我們可以使用以下幾行程式碼。
示例
import matplotlib.pyplot as plt import matplotlib.image as mpimg # Load the image img = mpimg.imread('Images/flowers.jpg') # Load image file # Display the image plt.imshow(img) plt.axis('off') # Turn off axis labels and ticks (optional) plt.show()
上述程式碼的關鍵點
matplotlib.image.imread() − 載入圖片檔案並將其作為陣列返回。應指定檔案路徑 ('image_path')。
plt.imshow() − 顯示由陣列表示的圖片。
plt.axis('off') − 關閉座標軸標籤和刻度,對於僅顯示圖片而不顯示座標軸是可選的。
輸出

自定義圖片顯示
我們可以根據需要透過以下提到的函式自定義圖片。
顏色圖 − 我們可以透過在imshow()中指定cmap引數來應用顏色圖以增強圖片視覺化效果。
顏色條 − 若要新增一個指示強度對映的顏色條,可以在imshow()之後使用plt.colorbar()。
示例
import matplotlib.pyplot as plt import matplotlib.image as mpimg # Load the image img = mpimg.imread('Images/flowers.jpg') # Load image file # Display the image plt.imshow(img, cmap = 'Oranges') plt.colorbar() # Turn on axis labels and ticks (optional) plt.axis('on') plt.show()
輸出

圖片處理
我們可以使用以下提到的函式對圖片進行處理。
裁剪 − 透過在將其傳遞給imshow()之前切片陣列來選擇圖片的特定部分。
調整大小 − 使用 Pillow、OpenCV 等各種影像處理庫在顯示圖片之前調整圖片大小。
示例
在這個例子中,我們正在操作圖片,並使用上述函式顯示圖片。
import matplotlib.pyplot as plt import matplotlib.image as mpimg import cv2 # Load the image img = mpimg.imread('Images/flowers.jpg') # Display the image with grayscale colormap and colorbar plt.imshow(img, cmap='gray') plt.colorbar() # Display only a portion of the image (cropping) plt.imshow(img[100:300, 200:400]) # Display a resized version of the image resized_img = cv2.resize(img, (new_width, new_height)) plt.imshow(resized_img) plt.show()
輸出

請記住,Matplotlib 的imshow()適用於基本的圖片顯示和視覺化。對於更高階的影像處理任務,例如調整大小、過濾等,建議使用 OpenCV 或 Pillow 等專用影像處理庫。