且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 matplotlib 中内联更改文本样式

更新时间:2023-01-27 12:14:10

Matplotlib 允许您使用 Latex.默认情况下未启用该功能,因此您必须先将其激活.

Matplotlib allows you to use latex. It is not enabled by default, so you have to activate it first.

示例:

import matplotlib.pyplot as plt

# activate usage of latex
plt.rcParams['text.usetex'] = True

# generate a simple graph
fig, ax = plt.subplots(1,1, figsize=(6,3))
ax.text(0.5, 0.5, r"\textit{\textbf{one}} two (on the axes)")
fig.text(1., 1., r"\textit{\textbf{one}} two (on the figure)",
        horizontalalignment='right', verticalalignment='top')

plt.show()

结果: