TeX
使用TeX对文本内容进行渲染,使用r"$$"的模式,非数字表达式以斜体输出,呈现印刷级别的文档效果。
# -*- coding: UTF-8 -*-
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams["font.sans-serif"] = ["SimHei"]
mpl.rcParams["axes.unicode_minus"] = False
x = np.linspace(-2*np.pi, 2*np.pi, 200)
y = np.sin(x)
plt.plot(x, y, label=r"$\sin(x)$")
plt.legend(loc="upper right")
plt.title(r"$\sin(x)$函数")
plt.show()
图例样式调整
# -*- coding: UTF-8 -*-
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams["font.sans-serif"] = ["SimHei"