【问题标题】:Align TeX equations in matplotlib在 matplotlib 中对齐 TeX 方程
【发布时间】:2011-08-29 10:57:06
【问题描述】:

我在 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,但我不太明白。

【问题讨论】:

    标签: python math matplotlib tex alignment


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-01-20
      • 1970-01-01
      • 2011-08-30
      • 2012-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-31
      • 2015-01-20
      相关资源
      最近更新 更多