在matplotlib中对齐TeX方程

发布于 2021-01-29 15:05:37

我有以下几行注释我的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,但我不完全得到它的权利。

关注者
0
被浏览
92
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    使用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 )



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看