How to display matrix in Matplotlib annotations

I am trying to build a matrix using Matplotlib-Plot annotations. Is it possible?

I tried with the most basic example, which all violates the plot:

ax.annotate(r"$ \begin{matrix} a & b & c \\
              d & e & f \\ 
              g & h & i \end{matrix} $", (0.25, 0.25),
              textcoords='axes fraction', size=20)

Edit:

Part of the problem was that I missed the "texlive-latex-extra", which contains the "type1cm", which is necessary for the correct display. See Also: Python: Cannot Display Tex in Matplotlib

+1
source share
1 answer

MatPlotLib uses its own set structure ( MathText ). Your LaTeX rendering system can be turned on rcParams['text.usetex'] = True.

, , - . \, \\ .

:

from matplotlib import rcParams

rcParams['text.usetex'] = True

ax.annotate(
    r"$ \begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} $",
    (0.25, 0.25),
    textcoords='axes fraction', size=20)

array, matrix, , LaTeX. matrix - amsmath - amsmath MatPlotLib LaTeX:

rcParams['text.latex.preamble'] = r'\usepackage{amsmath}'

matrix,

ax.annotate(
    r"$ \begin{matrix} a & b & c \\ d & e & f \\ g & h & i \end{matrix} $",
    (0.25, 0.25),
    textcoords='axes fraction', size=20)
+3

All Articles