2016-11-02 39 views
0

我不確定爲什麼會發生這種情況,當我嘗試在這裏給出我的代碼時,製作4張地圖(圖像)的2x2子圖。我覺得我誤解了一些東西。子圖不在Python中繪圖

import matplotlib.pyplot as plt 
img1=plt.imread('0507_1994_better_map.png') 
img3=plt.imread('0507_2015_better_map.png') 
img2=plt.imread('0810_1994_better_map.png') 
img4=plt.imread('0810_2015_better_map.png') 

plt.figure() 
plt.imshow(img1) 
plt.subplot(221) 
plt.axis('off') 
plt.imshow(img2) 
plt.subplot(222) 
plt.axis('off') 
plt.imshow(img3) 
plt.subplot(223) 
plt.axis('off') 
plt.imshow(img4) 
plt.subplot(224) 

plt.show() 

enter image description here

+0

請解釋什麼錯誤,你期待什麼,我們展示了所產生的圖等等。 *「爲什麼會發生這種情況」*相當隱晦。 – Bart

+1

問題描述非常糟糕。我可能會猜測你的意思:你錯過了第一個情節?在這種情況下,原因將是您首先顯示圖像,然後創建子圖。您需要撤消該訂單。 – ImportanceOfBeingErnest

+1

如上所述,您可以嘗試更清楚地描述問題。我注意到你在'plt.imshow'之後調用'plt.subplot',你必須先調用它。 – hashmuke

回答

-1

您應指定您繪製的東西,它應該被繪製前:

plt.figure() 
plt.subplot(221) # this comes first 
plt.imshow(img1) # this comes second 
plt.axis('off') 
...