Saving a image has no axis and no margin

When saving an image processed with matplotlib, the image axes and margins are not necessary. So I surveyed how to remove them and summarized them.

Code

from scipy.misc import imread
import matplotlib.pyplot as plt

img = imread('IMG_1382.JPG')
plt.imshow(img / 255.)
plt.axis('off')  # 1
plt.tick_params(labelbottom=False, labelleft=False, labelright=False, labeltop=False)  # 2
plt.savefig('IMG_1382_ex.JPG', bbox_inches='tight', pad_inches=0)  # 3

Points are the following.

  1. remove axes
  2. remove labels
  3. remove margin

Executable code is here. When $ test.py is input at terminal, the next image has no axis and no mergin is saved at the same directory.

f:id:Shoto:20180916010309j:plain

P.S. It works well on Windows, but remains small frame on Ubuntu. I don't know why.

References