MatPlotLib uses its own typesetting framework (MathText). Your system's LaTeX rendering can be enabled by, rcParams['text.usetex'] = True
.
The other problem that you have is a double-quoted multi-line string. This isn't really allowed without using a
, and that is difficult to manage with your existing \
.
Try this:
from matplotlib import rcParams
rcParams['text.usetex'] = True
ax.annotate(
r"$ egin{array}{ccc} a & b & c \ d & e & f \ g & h & i end{array} $",
(0.25, 0.25),
textcoords='axes fraction', size=20)
Here I have used the array
environment, rather than matrix
because I don't think the latter is a LaTeX built-in. If you really want matrix
--or other amsmath items--you can add the amsmath package to the MatPlotLib LaTeX preamble:
rcParams['text.latex.preamble'] = r'usepackage{amsmath}'
Then the matrix
environment will work,
ax.annotate(
r"$ egin{matrix} a & b & c \ d & e & f \ g & h & i end{matrix} $",
(0.25, 0.25),
textcoords='axes fraction', size=20)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…