如何使用 imshow 用 Matplotlib 繪製 Y 軸為非線性的影像?


若要使用 imshow() 方法繪製 Y 軸為非線性的影像,可執行以下步驟−

  • 設定圖形大小並調整子圖之間的邊距和周圍的邊距。
  • 將子圖新增到當前圖形。
  • 設定非線性 Y 軸刻度。
  • 使用 numpy 建立隨機資料點。
  • 以影像形式(即資料上的 2D 正則光柵)顯示資料。
  • 若要顯示圖形,請使用 show() 方法。

示例

import matplotlib.pyplot as plt
import numpy as np

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

ax = plt.subplot(111)
ax.yaxis.set_ticks([0, 2, 4, 8])

data = np.random.randn(5, 5)

plt.imshow(data, cmap='copper')

plt.show()

輸出

更新日期: 2021 年 8 月 3 日

802 次瀏覽

開啟你的 職業

完成課程獲得認證

開始
廣告
© . All rights reserved.