How can I have a proper LaTex compilation of a svg format Matlab plot?

17 views (last 30 days)
When I save my Matlab plots in svg format the objects containing texts such as legend, axis labels and the axis numbers are saved as texts and not paths which cause me problems when I try to compile the figures in svg format in Latex with Overleaf (these texts are not properly compiled and their format is not the desired one and the compiled figure is a mess). I think something changed in the Matlab svg renderizer because before all the figure was renderized equally and those texts were given as paths. If someone has idea of how can I fix this or if there are other options to save Matlab figures instead of .svg or .png in which the graphs lose a lot of quality. I would like to be similar to svg format and be able to compile with Overleaf with proper format and not having this issue.
  1 Comment
Ashok
Ashok on 4 Dec 2024
Hey Jorge,
Could you send the svg file as well as screenshots from latex, to better understand the problem?

Sign in to comment.

Answers (1)

Ashok
Ashok on 4 Dec 2024
Edited: Ashok on 4 Dec 2024
I encountered a similar issue when using SVGs with LaTeX. It seems that the SVG file created by MATLAB doesn't preserve the text format. However, when some text on the plot uses the 'latex' interpreter, all text seems to be exported as a path. Here's some example code and the corresponding figure in Overleaf:
Code:
x = 0:pi/10:2*pi;
y1 = sin(x);
y2 = sin(x-0.25);
y3 = sin(x-0.5);
figure
plot(x,y1,'g',x,y2,'b--o',x,y3,'c*')
xlabel("x values")
ylabel("y values")
fontname('Papyrus' )
title("Plot of sine waves")
text(0, 0, "", Interpreter="latex")
saveas(gcf, "testImage", 'svg')
LaTeX:
I have attached the SVG file for your reference. Alternatively, switching to an EPS file type works well with LaTeX. Here's a comparison of SVG, EPS, and PNG file formats for the same MATLAB figure, inserted into LaTeX without any scaling applied. It seems that EPS provides the best results.
MATLAB Figure:
LaTeX:
A MATLAB figure, 'fig', can be saved to a file 'filename' in colored EPS format using this command:
saveas(fig, filename, 'epsc');
For more information on other image format types available in MATLAB, check out this link:
I believe this will assist you!

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!