帶重音的文字#

Matplotlib 透過 TeX 數學文字或 Unicode 支援帶重音的字元。

使用數學文字,提供以下重音符號:\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()
$\ddot{o}\acute{e}\grave{e}\hat{O}\breve{i}\bar{A}\tilde{n}\vec{q}$

您也可以直接在字串中使用 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()
GISCARD CHAHUTÉ À L'ASSEMBLÉE

腳本總執行時間: (0 分鐘 1.637 秒)

由 Sphinx-Gallery 產生的圖庫