Matplotlib – 使用 Python 繪製圖像背景(譯文)


要繪製圖像背景,我們可以按照以下步驟進行:

  • 從檔案中將影像讀入陣列。
  • 使用範圍 [0, 300, 0, 300] 建立一個圖形(fig)並新增一組子圖(ax)。
  • 建立一個範圍 (300) 的陣列 x。
  • 使用 plot() 方法繪製 x,並設定 linestyle=dottedlinewidth=2color=red
  • 要顯示圖形,請使用 show() 方法。

示例

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
im = plt.imread("bird.jpg")
fig, ax = plt.subplots()
im = ax.imshow(im, extent=[0, 300, 0, 300])
x = np.array(range(300))
ax.plot(x, x, ls='dotted', linewidth=2, color='red')
plt.show()

輸出

更新時間:2021 年 5 月 6 日

19K+ 瀏覽量

開啟你的職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.