在 matplotlib 中使用 latex "eqnarray"-command 减少等号之间的间距?

Decrease spacing between equal signs using latex "eqnarray"-command in matplotlib?

我想在matplotlib中对齐等号。因此,我在 matplotlib 中使用 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()

结果如下所示:

如何减小等号附近的间距?

您需要加载 amsmath 包才能使用 'align'。 'eqnarray' 中白色 space 的问题在这里讨论:https://github.com/matplotlib/matplotlib/issues/4954。我猜至少在 matplotlib 1.2.1 中问题没有解决。

这应该给出相同的结果:

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