|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +r""" |
| 3 | +================================= |
| 4 | +Using accented text in matplotlib |
| 5 | +================================= |
| 6 | +
|
| 7 | +Matplotlib supports accented characters via TeX mathtext or unicode. |
| 8 | +
|
| 9 | +Using mathtext, the following accents are provided: \hat, \breve, \grave, \bar, |
| 10 | +\acute, \tilde, \vec, \dot, \ddot. All of them have the same syntax, |
| 11 | +e.g., to make an overbar you do \bar{o} or to make an o umlaut you do |
| 12 | +\ddot{o}. The shortcuts are also provided, e.g.,: \"o \'e \`e \~n \.x |
| 13 | +\^y |
| 14 | +""" |
| 15 | +from __future__ import unicode_literals |
| 16 | +import matplotlib.pyplot as plt |
| 17 | + |
| 18 | +# Mathtext demo |
| 19 | +fig, ax = plt.subplots() |
| 20 | +ax.plot(range(10)) |
| 21 | +ax.set_title(r'$\ddot{o}\acute{e}\grave{e}\hat{O}' |
| 22 | + r'\breve{i}\bar{A}\tilde{n}\vec{q}$', fontsize=20) |
| 23 | + |
| 24 | +# Shorthand is also supported and curly braces are optional |
| 25 | +ax.set_xlabel(r"""$\"o\ddot o \'e\`e\~n\.x\^y$""", fontsize=20) |
| 26 | +ax.text(4, 0.5, r"$F=m\ddot{x}$") |
| 27 | +fig.tight_layout() |
| 28 | + |
| 29 | +# Unicode demo |
| 30 | +fig, ax = plt.subplots() |
| 31 | +ax.set_title("GISCARD CHAHUTÉ À L'ASSEMBLÉE") |
| 32 | +ax.set_xlabel("LE COUP DE DÉ DE DE GAULLE") |
| 33 | +ax.set_ylabel('André was here!') |
| 34 | +ax.text(0.2, 0.8, 'Institut für Festkörperphysik', rotation=45) |
| 35 | +ax.text(0.4, 0.2, 'AVA (check kerning)') |
| 36 | + |
| 37 | +plt.show() |
0 commit comments