Matplotlib adjust figure margin

后端 未结 7 753
盖世英雄少女心
盖世英雄少女心 2021-01-31 15:48

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

7条回答
  •  醉梦人生
    2021-01-31 16:21

    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.

提交回复
热议问题