Matplotlib and Ipython-notebook: Displaying exactly the figure that will be saved

纵饮孤独 提交于 2019-11-26 21:04:01

As noted by @andrew, the ipython magics are enforcing bbox_inches='tight' by default. This can be overridden using other magics as explained in the ipython documentation:

%matplotlib inline
%config InlineBackend.print_figure_kwargs = {'bbox_inches':None}

produces an inline image identical to that produced by savefig.

The behavior is due to the fact that the magic %matplotlib inline defaults to using the bbox_inches='tight' when rendering inline.

I know you asked about changing the behavior of plt.show(), but alternatively, you could change the behavior of savefig() to use the same settings as the notbeook.

fig.savefig('mypath.png',dpi=300, facecolor='gray',  bbox_inches='tight')

New 'savefig' image:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!