2015-09-15 43 views
0

我需要在圖片上繪圖。我用這個代碼來顯示圖像:python劇情中的背景圖片

plt.figure() 
mngr = plt.get_current_fig_manager() 
fname = 'erausal-valence.jpg' 
image = Image.open(fname).convert("L") 
arr = np.asarray(image) 
plt.imshow(arr) 

在這個形象上我需要繪製一個數組建立與成分:

for i in range(0, len(BPM)):  
    for k in range(0, len(BPM)): 
     (X[k], Y[k]) = pol2cart(BPM[k], -SC[k]); 
     plt.plot(X[k], Y[k]) 

但圖顯示圖像和不顯示的情節X和Y陣列。

回答

0

X和Y的值是什麼?我已經使用了下面的代碼,並可以在圖像上繪製圖形。

import matplotlib.pyplot as plt 
import matplotlib.cbook as cbook 

imageFile = cbook.get_sample_data('ada.png') 
image = plt.imread(imageFile) 

plt.imshow(image) 

coords = [0, 100, 200, 300, 400, 500, 600] 

plt.plot(coords, coords, 'r--', linewidth=2) 
plt.show() 
0

要添加背景圖片,你必須添加此導入:

from matplotlib import cbook 

現在來填補它在後臺,你應該展現指令之前加上這些行:

imageFile = cbook.get_sample_data('<Path_to_your_image>') 
image = plt.imread(imageFile) 
plt.imshow(image)