如何在 Matplotlib 中编写自己的 LaTeX 序言?
matplotlibpythondata visualization更新于 2025/7/11 5:00:17
要在 Matplotlib 中编写自己的 LaTeX 序言,我们可以采取以下步骤 −
- 设置图形大小并调整子图之间和周围的填充。
- 使用 numpy 创建 x 和 y 随机数据点。
- 使用 plot() 方法绘制 x 和 y 数据点。使用 LaTex 格式设置标签。label="$y=e^{x}$"
- 使用 legend() 方法在图形上放置图例。
- 要显示图形,请使用 show() 方法。
示例
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(-10, 10, 100)
y = np.exp(x)
plt.plot(x, y, color='red', label="$y=e^{x}$")
plt.legend(loc='upper right')
plt.show()
输出

相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

