import matplotlib.pyplot as plt
import numpy as np
启用LaTeX渲染
plt.rcParams[‘text.usetex’] = True
plt.rcParams[‘font.family’] = ‘serif’
生成示例数据
x = np.linspace(0, 10, 100)
y = np.sin(x)
绘制图形
plt.plot(x, y)
添加标题和标签,使用LaTeX语法显示公式
plt.title(r’函数
y
=
sin
(
x
)
y = \sin(x)
y=sin(x)‘)
plt.xlabel(r’
x
x
x’)
plt.ylabel(r’
y
y
y’)
在图中添加注解,显示公式 a 1 a_1 a1
plt.annotate(r’公式示例:
a
1
a_1
a1’, xy=(3, 0.5), xytext=(5, 0.8),
arrowprops=dict(facecolor=‘black’, shrink=0.05))
显示图形
plt.show()