Error:plt.savefig() 輸出空白圖片
代碼
import matplotlib.pyplot as plt
...
plt.imshow(image.read_value()[0])
plt.show()
plt.savefig('xxx.png')
原因
plt.show() 之后會(huì)新建一個(gè)空白的圖像(plt),其后的代碼將畫在這個(gè)空白圖像上,所以保存的圖像是空白的。
解決方案
先保存圖片,最后show,即:將 plt.savefig() 放在 plt.show() 之前。
plt.imshow(image.read_value()[0])
plt.savefig('xxx.png')
plt.show()
Reference: https://stackoverflow.com/questions/9012487/matplotlib-pyplot-savefig-outputs-blank-image