Matplotlib – 使用 Python 繪製圖像背景(譯文)
要繪製圖像背景,我們可以按照以下步驟進行:
- 從檔案中將影像讀入陣列。
- 使用範圍 [0, 300, 0, 300] 建立一個圖形(fig)並新增一組子圖(ax)。
- 建立一個範圍 (300) 的陣列 x。
- 使用 plot() 方法繪製 x,並設定 linestyle=dotted、linewidth=2 和 color=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()輸出

廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP