問題:matplotlib 及其他一些畫圖工具茅逮,在保存plot的時候冯事,總會出現(xiàn)一些問題,例如圖片周邊包含多余空白區(qū)域德绿。這里主要解決這個問題.
我們保存plot的圖片:
plt.figure(figsize=(15,8))
p = plt.subplot(111)
plt.savefig('image_name')
會得到下面的圖像,圖片周圍存在一些不必要的空白區(qū)域 redundant padding.
image with redundant padding
這些padding會占用大量的空間,壓縮我們關(guān)注的圖片移稳。去掉這些padding:
plt.figure(figsize=(15,8))
p = plt.subplot(111)
plt.savefig('image_name', ,bbox_inches='tight')
bbox的意思是bounding box, tight就不用說了蕴纳,讓保存的圖片更加緊促「隽唬可以得到:
image with padding region removed
需要注意的是:bbox_inches ='tight' 只能用于保存圖片袱蚓,不能用于顯示。