Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0aded83

Browse files
timhoffmtacaswellQuLogic
committed
Add note on interaction between text wrapping and bbox_inches='tight'
Co-authored-by: Thomas A Caswell <[email protected]> Co-authored-by: Elliott Sales de Andrade <[email protected]>
1 parent 14ecfcc commit 0aded83

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

examples/text_labels_and_annotations/autowrap.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
66
Matplotlib can wrap text automatically, but if it's too long, the text will be
77
displayed slightly outside of the boundaries of the axis anyways.
8+
9+
Note: Auto-wrapping does not work together with
10+
``savefig(..., bbox_inches='tight')``. The 'tight' setting rescales the canvas
11+
to accommodate all content and happens before wrapping. This affects
12+
``%matplotlib inline`` in IPython and Jupyter notebooks where the inline
13+
setting uses ``bbox_inches='tight'`` by default when saving the image to
14+
embed.
815
"""
916

1017
import matplotlib.pyplot as plt

lib/matplotlib/text.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,14 @@ def set_wrap(self, wrap):
544544
Parameters
545545
----------
546546
wrap : bool
547+
548+
Notes
549+
-----
550+
Wrapping does not work together with
551+
``savefig(..., bbox_inches='tight')`` (which is also used internally
552+
by ``%matplotlib inline`` in IPython/Jupyter). The 'tight' setting
553+
rescales the canvas to accommodate all content and happens before
554+
wrapping.
547555
"""
548556
self._wrap = wrap
549557

0 commit comments

Comments
 (0)