LaTeX interpreter on a legend

160 次查看(过去 30 天)
John
John 2015-3-4
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?

回答(1 个)

Andrew Newell
Andrew Newell 2015-3-4
编辑:Andrew Newell 2015-3-4
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 个评论
John
John 2015-3-4
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 2015-3-4
If you're using plot2svg from the File Exchange, your best bet is probably to ask its creator.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by