You are reading an old version of the documentation (v1.5.0). For the latest version see https://matplotlib.org/stable/

We're updating the default styles for Matplotlib 2.0

Learn what to expect in the new updates

matplotlib

Previous topic

text_labels_and_annotations Examples

Next topic

text_labels_and_annotations example code: rainbow_text.py

This Page

text_labels_and_annotations example code: autowrap_demo.pyΒΆ

(Source code, png, hires.png, pdf)

../../_images/autowrap_demo.png
"""
Auto-wrapping text demo.
"""
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()

Keywords: python, matplotlib, pylab, example, codex (see Search examples)