CFS CFS - 8 months ago 51
Python Question

matplotlib: space between point and decimal digits in TeX mode

Why has matplotlib inserted a space between the decimal digit and the point in the legend? How do I get rid of it?

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 1, 100)
y = np.sin(x)
plt.plot(x, y, label='$a = 1.0$')
plt.legend(loc='lower right')



It seem to be a bug in matplotlib. As far as I understand, the fix is available but not yet merged with the default branch.

As for now, you can use usetex option to use the real TeX (if it is available in your environment).

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np

mpl.rcParams['text.usetex'] = True
plt.figure(figsize=(10, 10))
x = np.linspace(0, 1, 100)
plt.legend(loc='lower right', prop={'size':60})

render with tex