.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/text_labels_and_annotations/autowrap.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. meta:: :keywords: codex .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_text_labels_and_annotations_autowrap.py: ================== Auto-wrapping text ================== Matplotlib can wrap text automatically, but if it's too long, the text will be displayed slightly outside of the boundaries of the axis anyways. Note: Auto-wrapping does not work together with ``savefig(..., bbox_inches='tight')``. The 'tight' setting rescales the canvas to accommodate all content and happens before wrapping. This affects ``%matplotlib inline`` in IPython and Jupyter notebooks where the inline setting uses ``bbox_inches='tight'`` by default when saving the image to embed. .. GENERATED FROM PYTHON SOURCE LINES 16-33 .. image-sg:: /gallery/text_labels_and_annotations/images/sphx_glr_autowrap_001.png :alt: autowrap :srcset: /gallery/text_labels_and_annotations/images/sphx_glr_autowrap_001.png, /gallery/text_labels_and_annotations/images/sphx_glr_autowrap_001_2_00x.png 2.00x :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt fig = plt.figure() plt.axis((0, 10, 0, 10)) t = ("This is a really long string that I'd rather have wrapped so that it " "doesn't go outside of the figure, but if it's long enough it will go " "off the top or bottom!") plt.text(4, 1, t, ha='left', rotation=15, wrap=True) plt.text(6, 5, t, ha='left', rotation=15, wrap=True) plt.text(5, 5, t, ha='right', rotation=-15, wrap=True) plt.text(5, 10, t, fontsize=18, style='oblique', ha='center', va='top', wrap=True) plt.text(3, 4, t, family='serif', style='italic', ha='right', wrap=True) plt.text(-1, 0, t, ha='left', rotation=-15, wrap=True) plt.show() .. _sphx_glr_download_gallery_text_labels_and_annotations_autowrap.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: autowrap.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: autowrap.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_