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()
![Python: matplotlib繪製出的圖表如何插入背景圖? img = plt.imread('background_image.png') ; ax.imshow(img, extent=[0, 10, -1.2, 1.2], aspect='auto', alpha=0.5) - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2023/02/20230216183536_29.png)
輸出:
![Python: matplotlib繪製出的圖表如何插入背景圖? img = plt.imread('background_image.png') ; ax.imshow(img, extent=[0, 10, -1.2, 1.2], aspect='auto', alpha=0.5) - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2023/02/20230216183434_51.png)
推薦hahow線上學習python: https://igrape.net/30afN





![Python: pandas.DataFrame()處理雙維度資料,dict跟2D list轉為DataFrame有何差別?如何用index及columns屬性客製化index跟欄位名稱?df.index = [“一”,”二”,”三”,”四”] ; df.columns = 使用.head(n) ; .tail(m) ;取首n列,尾m列; .at[index,欄位名稱] 取單一資料 ; .iat[index,欄位順序] 取單一資料 ; .loc[index,欄位名稱] 取資料 ; .iloc[index,欄位順序];df.iloc[ [0,1],[0,2]])取資料 ; df.iloc[ 0:3,0:2]切片 Python: pandas.DataFrame()處理雙維度資料,dict跟2D list轉為DataFrame有何差別?如何用index及columns屬性客製化index跟欄位名稱?df.index = [“一”,”二”,”三”,”四”] ; df.columns = 使用.head(n) ; .tail(m) ;取首n列,尾m列; .at[index,欄位名稱] 取單一資料 ; .iat[index,欄位順序] 取單一資料 ; .loc[index,欄位名稱] 取資料 ; .iloc[index,欄位順序];df.iloc[ [0,1],[0,2]])取資料 ; df.iloc[ 0:3,0:2]切片](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2022/11/20221111093547_79.png?quality=90&zoom=2&ssl=1&resize=350%2C233)




近期留言