Matplotlib raw latex "\ epsilon" only gives "\ varepsilon"

I use Matplotlib to analyze the results and create numbers. I need Greek characters in the legend and axis labels, including $ \ epsilon $. However, the resulting text does not distinguish between "normal" \ epsilon and \ varepsilon --- both are displayed as \ varepsilon. Here is a minimal example:

import numpy as np
from pylab import *
import matplotlib.pyplot as plt

t = np.arange(0.0, 1.0 + 0.01, 0.01)
s = np.cos(4 * np.pi * t) + 2

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot(t, s, 'k-', linewidth=2.0, label=r'$\epsilon$, $\varepsilon$, $\phi$, $\varphi$, $\sigma$, $\varsigma$')
plt.title(r'$\epsilon$, $\varepsilon$, $\phi$, $\varphi$, $\sigma$, $\varsigma$')
plt.xlabel(r'$t [M]$')
plt.ylabel(r'$\epsilon$, $\varepsilon$, $\phi$, $\varphi$, $\sigma$, $\varsigma$')
ax.legend(ncol=2, loc='lower left', fancybox=True)
plt.show()

When I process this on my Macbook (OS X El Capitan with Macports installations for TexLive and py27-matplotlib), everything displays correctly except \ epsilon.

ETA: The code does the right thing on another machine (Scientific Linux).

+4
source share
2 answers

TeX script. Matplotlib MathText, LaTeX, UTF8. MathText :

enter image description here

, "\ varepsilon" , "\ epsilon". , , "" .

plt.rcParams["mathtext.fontset"] = "cm"

:

enter image description here


Latex , matplotlib . -
plt.rcParams["text.usetex"] =True

script. TeX.
, "\ varepsilon" "\ epsilon" .

enter image description here

+4

matplotlib ( , ). "" -, plt.rc('text', usetex=True) /. script , .

edit: mathtext.

+2

Source: https://habr.com/ru/post/1676169/


All Articles