1

I would like to preserve latex annotations format in .svg in a matplotlib plot.

I have the following example:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['text.usetex'] = True
mpl.rcParams['text.latex.preamble'] = r'\usepackage{{amsmath}}'

plt.rc('text', usetex=True)


my_str =  r"$\begin{bmatrix}   0 & 1 & 2 \\   3 & 4 & 5 \\   6 & 7 & 8 \\ \end{bmatrix}$"
            
plt.plot(np.arange(10), np.arange(10))
plt.text(0.5,0.5, s=my_str)

which plots:

enter image description here

When I save the image as .svg the matrix gets "squished":

enter image description here

How can I fix that? If I save to .pdf, png I have no problem with the annotation.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
R. Smith
  • 103
  • 7
  • [This post](https://stackoverflow.com/questions/50506076/is-there-an-efficient-way-to-store-2d-plots-as-a-vector-graphic-in-python) might help – paime Aug 28 '23 at 07:07

0 Answers0