Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

python - Align TeX equations in matplotlib

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

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"
oindent$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 egin{align}, &-placement, but I don't quite get it right.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"egin{eqnarray*}R_L&= 0\ V_2&= 1\ I_2&= 2end{eqnarray*}")

#notes = r"
oindent$$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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...