The following code gives me a plot with significant margins above and below the figure. I don\'t know how to eliminate the noticeable margins. subplots_adjust
does
I think what you need is, and it works well for me.
plt.axis('tight')
This command will automatically scale the axis to fit tightly to the data. Also check the answer of Nuno Aniceto for a customized axis. The documents are in https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.axis.
Be aware that
plt.savefig(filename, bbox_inches='tight')
will help remove white space of all the figure including labels, etc, but not the white space inside the axes.