TeX (LaTeX math mode) symbols in legends and labels in MATLAB figures
古いコメントを表示
I am plotting some data which includes estimates of some parameters. I want to describe the estimates by using \hat on the parameter symbols. This I have to do in legends and axis labels fields. I could not fix this matter despite some experiments using information from MATLAB help. Any idea, please to fix this problem. I really appreciate help on this matter which will improve the look of my presentation. Shah
採用された回答
その他の回答 (6 件)
Mikhail Smirnov
2017 年 2 月 10 日
You can do like this
plot(1:10);
leg1 = legend('$\bar{x}$','$\tilde{x}$','$\hat{x}$');
set(leg1,'Interpreter','latex');
set(leg1,'FontSize',17);

works well
4 件のコメント
Walter Roberson
2017 年 9 月 1 日
Ahmad Alsharif comments to Mikhail Smirnov:
This helped me in creating multi line legend with latex as interpreter
Thomas Gillet
2017 年 12 月 17 日
Hello Everyone,
When I use Latex interpreter, I am not able to change the font of the legend as you mentionned with set(leg1,'FontSize',17); Have you any idea ? Thank's, Thomas
Mario
2023 年 4 月 17 日
Unfortunately this doesn't work for me.
I am tried using annotations and legends to write v_{mean on} as v_on to save figure space.
I tried several things:
lgd = legend{'on', 'off', '$$\bar{\itv}$$_{on}', 'v_{mean off}'}
lgd = legend{'on', 'off', '$\bar{\itv}$_{on}', 'v_{mean off}'}
lgd = legend{'on', 'off', '$\bar{v}$_{on}', 'v_{mean off}'}
lgd = legend{'on', 'off', ['$\bar{v}$','_{on}'], 'v_{mean off}'}
or
lgd = legend{'on', 'off', '$$\overline{\itv}$$_{on}', 'v_{mean off}'}
lgd = legend{'on', 'off', '$\overline{\itv}$_{on}', 'v_{mean off}'}
lgd = legend{'on', 'off', '$\overline{v}$_{on}', 'v_{mean off}'}
lgd = legend{'on', 'off', ['$\overline{\itv}$','_{on}'], 'v_{mean off}'}
won't work.
It would just add the $$\overline... to the legend text.
I tried both latex and tex interpreter.
I am using MATLAB v 2018b
I figured it out:
lgd = legend('on','off', '$\overline{v}_{on}$', '$\overline{v}_{off}$')
But now my font is not Calibri anymore. it's rather looking like Times New Roman or sth.
set(lgd, 'interpreter', 'latex', 'FontName', 'Calibri')
won't help :(
is there a problem with Calibri + Latex?
Frederik van der Walt
2012 年 4 月 4 日
編集済み: KSSV
2022 年 5 月 26 日
l= legend(['$\hat{\psi}$']);
set(l,'Interpreter','Latex');
Jordan Brel Ngako Kadji
2020 年 5 月 7 日
0 投票
Once I had this problem, I was writing in German and because the german letter 'ä' was not recognised all the latex commands were ignored.
1 件のコメント
Rostislav Lebedev
2022 年 3 月 16 日
Try this
title('Verkehrstr\"ager', 'Interpreter', 'latex');
Richard Ulbricht
2022 年 12 月 13 日
Put this in front of your plotting commands, if you want it for all plots:
set(groot,'defaultLegendInterpreter','latex');
1 件のコメント
Yan Gao
2023 年 7 月 4 日
This is the best solution! Thanks, Richard!
カテゴリ
ヘルプ センター および File Exchange で Graphics Object Properties についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

