2016-08-18 2 views
1

matplotlibの等号を整列したいと思います。私は等号の近くで間隔を小さくするにはどうすればよい enter image description herematplotlibでラテックス "eqnarray"コマンドを使用して等号間の間隔を減らしますか?

:結果は次のようになります

import matplotlib.pyplot as plt 
from matplotlib import rc 

rc('text', usetex=True) 
rc('font', size  = 7) 

fig = plt.figure(figsize=(3,2)) 
ax = fig.add_subplot(111)  

ax.text(0.5,0.5 ,r'\begin{eqnarray*}' +\ 
      r'M    &=& 0.95' + '\\\\' +\ 
      r'\xi    &=& 0.5' + '\\\\' +\ 
      r'\mu    &=& 0.1' + '\\\\' +\ 
      r'a/b    &=& 0' + '\\\\' +\ 
      r'\delta_{99}/L &=& 0' +\ 
      r'\end{eqnarray*}', 
      verticalalignment='center', 
      horizontalalignment='center') 

plt.savefig('output.pdf') 
plt.show() 

:したがって、私はmatplotlibの中eqnarray環境を使用していますか?

+0

\\\\'' 'R'Mによって:

これは、同じ結果を与える必要があります&=&0.95 \\ ''、それは' r'の素晴らしいところです;) – Luis

+0

@Luis:コード内で見た目は良くなりますが、出力は同じです。 – malohm

+0

[OK]を、このアプローチに従って、 '整列'と一緒に働いている:https://stackoverflow.com/questions/30515888/align-latex-math-text-in-matplotlib-text-box – malohm

答えて

1

「整列」を使用するには、amsmathパッケージをロードする必要があります。 'eqnarray'の空白に関する問題については、ここで説明します:https://github.com/matplotlib/matplotlib/issues/4954。少なくともmatplotlib 1.2.1では問題は解決していないと思います。あなたは、生の文字列 `R'M&=&0.95' + 'に置き換えることができ

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

preamble = { 
    'text.usetex' : True, 
    'font.size' : 7, 
    'text.latex.preamble': [ 
     r'\usepackage{amsmath}', 
     ], 
    } 
plt.rcParams.update(preamble) 

fig = plt.figure(figsize=(3.,2.)) 
ax = fig.add_subplot(111) 

ax.text(0.5,0.5 ,r'\begin{align*}' +\ 
      r'M    &= 0.95 \\' +\ 
      r'\xi   &= 0.5 \\' +\ 
      r'\mu   &= 0.1 \\' +\ 
      r'a/b   &= 0 \\' +\ 
      r'\delta_{99}/L &= 0  ' +\ 
      r'\end{align*}', 
      verticalalignment='center', 
      horizontalalignment='center') 



plt.savefig('output.pdf') 
plt.show() 

enter image description here

関連する問題