import matplotlib.pyplot as plt
import numpy as np
# 生成 x, y 座標軸數據
x = np.linspace(0, 10, 100)
y = np.sin(x)
# 讀取背景圖
img = plt.imread(‘background_image.png’)
# 設置圖片大小和座標軸範圍
fig, ax = plt.subplots(figsize=(8, 6))
ax.set_xlim([0, 10])
ax.set_ylim([-1.2, 1.2])
# 繪製背景圖
ax.imshow(img, extent=[0, 10, -1.2, 1.2], aspect=’auto’, alpha=0.5)
# 繪製數據
ax.plot(x, y)
# 顯示圖形
plt.show()
輸出:
推薦hahow線上學習python: https://igrape.net/30afN