python - 在 matplotlib 中对齐 TeX 方程

标签 python math matplotlib tex alignment

我有以下行在我的 matplotlib 绘图上注释 TeX:

import matplotlib.pyplot as plt
from matplotlib import rc

rc('text', usetex=True)
rc('font', family='serif')

r = 1
v = 2
i = 3

notes = r"\noindent$R_L = {0}\\ V_2 = {1}\\ I_2 = {2}$".format(r, v, i)
plt.annotate(notes, xy=(5,5), xytext=(7,7))
plt.show()

如何使等号彼此对齐?我尝试了几种方法,例如 \begin{align}&-placement,但我不太正确。

最佳答案

使用eqnarray。 您的代码的简化版本:

#!/usr/bin/python
import matplotlib.pyplot as plt
from matplotlib import rc

rc('text', usetex=True)
rc('font', family='serif')

r = 1
v = 2
i = 3

plt.plot([1,2,3],[2,3,4],'ro-')

plt.text(2,2,r"\begin{eqnarray*}R_L&= 0\\ V_2&= 1\\ I_2&= 2\end{eqnarray*}")

#notes = r"\noindent$$R_L = {0}\\ V_2 = {1}\\ I_2 = {2}$$".format(r, v, i)
#plt.annotate(notes, xy=(5,5), xytext=(7,7))
plt.show()

为了让它工作,我必须安装 dvipng(如这里所建议的那样,http://matplotlib.sourceforge.net/users/usetex.html)

关于python - 在 matplotlib 中对齐 TeX 方程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6068827/

相关文章:

python - 在图像中发现不完全相同的模板

python - 迁移中的 Django 日期时间默认值

python - Python-实现自定义异常

java - 通过经验点相关性计算数字

javascript - 基于多条件/因素的排名算法

python - Matplotlib 散点图;颜色作为第三个变量的函数

python - matplotlib 中的自定义对数轴缩放

python - (215 :Assertion failed) type == CV_32FC1 || type == CV_32FC2 || type == CV_64FC1 || type == CV_64FC2 in function 'dft'

python - 欧拉计划 47 查找包含 4 个因子的所有数字

python - 设置 matplotlib 图形/轴属性的首选方法