How to disable bbox_inches='tight' when working with matplotlib inline in ipython notebook

后端 未结 2 778
悲哀的现实
悲哀的现实 2021-01-05 22:44

When work with matplotlib inline backend in ipython notebook, the default behavior is using bbox_inches=\'tight\' to generate the embedded png image internally via savefig()

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-05 23:29

    There's a fuller answer here: Matplotlib and Ipython-notebook: Displaying exactly the figure that will be saved

    The trick is to turn off the bbox_inches='tight' setting in ipython. It's a bit awkward to do temporarily, but just run the IPython magic in a block: %config InlineBackend.print_figure_kwargs = {'bbox_inches':None}

    If you want to switch back to the normal way, where axis labels are automatically never cut, you can run %config InlineBackend.print_figure_kwargs = {'bbox_inches':'tight'} but it has to be after the block where you do the plotting that needs precise bounding boxes.

提交回复
热议问题