备注
前往结尾 下载完整示例代码。
带重音的文本#
Matplotlib 通过 TeX mathtext 或 Unicode 支持带重音符号的字符。
使用 mathtext,提供了以下重音符号:hat, breve, grave, bar, acute, tilde, vec, dot, ddot。它们都有相同的语法,例如 bar{o} 生成“o 上划线”,ddot{o} 生成“o 分音符”。还支持快捷方式,如 "o 'e `e ~n .x ^y。
import matplotlib.pyplot as plt
# Mathtext demo
fig, ax = plt.subplots()
ax.plot(range(10))
ax.set_title(r'$\ddot{o}\acute{e}\grave{e}\hat{O}'
r'\breve{i}\bar{A}\tilde{n}\vec{q}$', fontsize=20)
# Shorthand is also supported and curly braces are optional
ax.set_xlabel(r"""$\"o\ddot o \'e\`e\~n\.x\^y$""", fontsize=20)
ax.text(4, 0.5, r"$F=m\ddot{x}$")
fig.tight_layout()

你也可以直接在字符串中使用Unicode字符。
fig, ax = plt.subplots()
ax.set_title("GISCARD CHAHUTÉ À L'ASSEMBLÉE")
ax.set_xlabel("LE COUP DE DÉ DE DE GAULLE")
ax.set_ylabel('André was here!')
ax.text(0.2, 0.8, 'Institut für Festkörperphysik', rotation=45)
ax.text(0.4, 0.2, 'AVA (check kerning)')
plt.show()