TeX (LaTeX math mode) symbols in legends and labels in MATLAB figures
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (6)
Mikhail Smirnov
el 10 de Feb. de 2017
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 comentarios
Walter Roberson
el 1 de Sept. de 2017
Ahmad Alsharif comments to Mikhail Smirnov:
This helped me in creating multi line legend with latex as interpreter
Thomas Gillet
el 17 de Dic. de 2017
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
el 17 de Abr. de 2023
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
el 4 de Abr. de 2012
Editada: KSSV
el 26 de Mayo de 2022
l= legend(['$\hat{\psi}$']);
set(l,'Interpreter','Latex');
Shah
el 23 de Nov. de 2011
0 votos
Jordan Brel Ngako Kadji
el 7 de Mayo de 2020
0 votos
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 comentario
Rostislav Lebedev
el 16 de Mzo. de 2022
Try this
title('Verkehrstr\"ager', 'Interpreter', 'latex');
Richard Ulbricht
el 13 de Dic. de 2022
Put this in front of your plotting commands, if you want it for all plots:
set(groot,'defaultLegendInterpreter','latex');
1 comentario
Yan Gao
el 4 de Jul. de 2023
This is the best solution! Thanks, Richard!
Categorías
Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

