开发者

Align TeX equations in matplotlib

开发者 https://www.devze.com 2023-03-07 00:45 出处:网络
I have the following lines to annotate TeX on my matplotlib plot: import matpl开发者_Python百科otlib.pyplot as plt

I have the following lines to annotate TeX on my matplotlib plot:

import matpl开发者_Python百科otlib.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()

How do I make the equals signs align to each other? I experimented with several methods like \begin{align}, &-placement, but I don't quite get it right.


Use eqnarray. A simplified version of your code:

#!/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()

To get it working I had to install dvipng (as suggested here, http://matplotlib.sourceforge.net/users/usetex.html)

0

精彩评论

暂无评论...
验证码 换一张
取 消