The effect of pad_inches in Python Matplotlib.pyplot


The results are:





This page shows how to change pad_inches and how it affect on the saved figure in python and matplotlib.pyplot.
In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
In [2]:
x = np.linspace(0,1,100)
y1 = x**2
y2 = x**0.5
In [3]:
for pad in [0.00,0.02,0.05]:
    plt.figure(facecolor="w")
    plt.plot(x,y1,color="r")
    plt.plot(x,y2,color="b")
    plt.xlabel("xxx")
    plt.ylabel("yyy")
    plt.savefig("pad_%04d.png"%(pad*1000),bbox_inches="tight",pad_inches=pad)
    # Note: The paddings of displayed figures in the notebook doesn't change.