2013-05-26 134 views
0

我有一個形狀爲15x30的數組,並且想要在pylab模式下將其保存爲pseudocolor plot,imsave()。然而,產生的輸出圖像的大小是15x30px。我嘗試設置dpi參數,但它沒有幫助,也沒有任何其他參數可以改變圖像大小。設置imsave()圖像輸出的大小

那麼如何從陣列中保存僞彩色圖像,使用imsave()並更改輸出圖像的大小?

+0

我不知道正是你正在嘗試做的。 – tacaswell

+0

http://matplotlib.org/api/pyplot_api.html?highlight=imsave#matplotlib.pyplot.imsave如果您注意到文檔說明'DPI存儲在文件的元數據中。這不會影響輸出圖像的分辨率。「 – tacaswell

+0

@tcaswell:取而代之的是15x30我想將圖像輸出爲150x300px的大小,所以相反,每個數組一個像素,每個數組值可以得到10x10px,就像我在使用'pcolor()'時在plot窗口中顯示的那樣。 – theta

回答

0

一個非常哈克解決這個只是擴展您的數據:

data = rand(10, 15) 
new_data = np.zeros(np.array(data.shape) * 10) 

for j in range(data.shape[0]): 
    for k in range(data.shape[1]): 
     new_data[j * 10: (j+1) * 10, k * 10: (k+1) * 10] = data[j, k] 

imsave(new_data) 
+0

:)我希望(d)有更簡單的方法,而不需要重塑 – theta

+0

,你可能想挖入PIL,或者在保存之後使用imagemagik。 – tacaswell

+0

這是一個好主意。這裏是PIL oneliner:'Image.fromarray(data).convert('RGB')。resize((150,300))。save('data.png')' – theta

相關問題