LaTeX interpreter on a legend

149 views (last 30 days)
John
John on 4 Mar 2015
Commented: Andrew Newell on 4 Mar 2015
I want the greek letter on my legend to look like as it does in LaTeX. Here is the code:
clc;
clear all;
phi=[1/2,1/3,1/4];
l=-0.1:.05:.1;
p = @(x,phi,l) 1/3.*(exp(x.^(phi))-1)./(exp(x.^(phi))+1) + l;
x=linspace(0,.2,101);
for k2 = 1:length(l)
figure(k2)
legendCounter = 1;
for k1 = 1:length(phi)
pValues = p(x,phi(k1),l(k2));
if any(pValues >= 0)
plot(x, pValues)
drawnow;
hold all
ar{legendCounter} = sprintf('{\\it\\phi_{state} =}%s',rats(phi(k1),3));
legendCounter = legendCounter + 1;
end
end
grid
axis([0 .21 0 .25])
hold off
legend(ar, 'Location','best')
plot2svg(['a=',num2str(k2),'.svg'])
end
Even though the greek letter looks fine on the matlab screen, when I see the resulting .svg file, it looks different. Is there any way to adjust this?

Answers (1)

Andrew Newell
Andrew Newell on 4 Mar 2015
Edited: Andrew Newell on 4 Mar 2015
You could try setting the interpreter to LaTeX:
legend(ar, 'Location','best','Interpreter','latex')
For this to work, you'll have to reformat the equation so there are dollar signs around it:
ar{legendCounter} = sprintf('$\\phi_\\mathrm{state} =%s$',rats(phi(k1),3));
While I was at it, I made the subscript into Roman characters because that is better style when the subscript is not a variable.
  2 Comments
John
John on 4 Mar 2015
The problem is in the .svg file. Somehow the .svg shows something different, even after setting the LaTeX interpreter like you did (see attached file).
Andrew Newell
Andrew Newell on 4 Mar 2015
If you're using plot2svg from the File Exchange, your best bet is probably to ask its creator.

Sign in to comment.

Categories

Find more on Labels and Annotations 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!