設定 Matplotlib 中影像的顏色圖


要設定影像的顏色圖,我們可以採取以下步驟 −

  • 設定圖形大小並調整子圖之間的邊距和周圍的邊距。
  • 從檔案中讀取影像並將其放入陣列中。
  • 挑選資料的其中一個通道。
  • 將資料顯示為影像,即,在具有“熱”顏色圖的 2D 常規光柵上
  • 關閉軸。
  • 若要顯示圖形,請使用 show() 方法。

示例

from matplotlib import pyplot as plt, image as mimg

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

img = mimg.imread('bird.jpg')
lum_img = img[:, :, 0]

plt.imshow(lum_img, cmap="hot")

plt.axis('off')

plt.show()

輸出

更新於: 2021-06-05

2K+ 瀏覽量

開啟你的 事業

完成課程獲取認證

開始
廣告
© . All rights reserved.