exportgraphics function output has incorrect font and spacing between characters

I'm exporting a figure of a plot using the exportgraphics function. For both vector .pdf and raster .png files, the sans serif LaTeX font is not shown correctly in both cases.
Snippet:
exportgraphics(fig, ...
'output.png', ...
'Resolution', 300)
exportgraphics(fig, ...
'output.pdf', ...
'ContentType', 'vector')
Where 'fig' is the figure object in question. Also, MATLAB shows the following warning:
% Error updating Text.
% Font cmss10 is not supported.
Below is a comparison of what I see in MATLAB and what the exported .png looks like.
MATLAB:
PNG output:
The vector output in PDF looks just like the PNG.

回答 (1 件)

Avni
Avni 2023 年 10 月 19 日
Hi Johann,
I understand that facing some problem while exporting the plotted graph with Sans Serif Latex font.
To achieve this, please refer to the following code as example:
fig = figure;
plot(magic(5));
xlabel("testing (X)", "FontName","SansSerif", "Interpreter","latex")
ylabel("testing (Y)", "FontName","SansSerif", "Interpreter","latex")
ax = gca;
exportgraphics(ax, 'output.png','Resolution', 300)
exportgraphics(ax,'output.pdf', 'ContentType', 'vector')
By following these steps, you should be able to export a figure with labels in sans serif LaTeX font in both JPG and PDF formats using “exportgraphicsfunction in MATLAB.
You can refer to these MATLAB documentations for more information:
I hope this helps.

4 件のコメント

Johann Hemmer
Johann Hemmer 2023 年 10 月 22 日
編集済み: Johann Hemmer 2023 年 10 月 22 日
Thanks for your help, Avni.
Unfortunately, if you look closely in the image you uploaded yourself, you will notice that the font family of the labels is LaTeX's Serif font, and not the Sans Serif one. That is even stranger since the ticks are the correct Sans Serif font. I tested your code and got the same result.
Liam
Liam 2024 年 1 月 6 日
Hi @Johann, did you find a solution to this problem? I am coming up with the same issue.
Johann Hemmer
Johann Hemmer 2024 年 10 月 1 日
編集済み: Johann Hemmer 2024 年 10 月 1 日
Hi @Liam! No, sorry. I switched to Python. Good luck!
Johann Hemmer
Johann Hemmer 2025 年 3 月 19 日
@Liam, hopefully you were able to fix this or you moved on. However, if you're still facing this issue, how I've dealt with it since then is to export all graphics as PDFs and then open them in InkScape and correct or improve them there, since it is so much easier.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangePrinting and Saving についてさらに検索

製品

リリース

R2023b

質問済み:

2023 年 10 月 9 日

コメント済み:

2025 年 3 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by