LaTeX interpreter on a legend

조회 수: 208 (최근 30일)
John
John 2015년 3월 4일
댓글: Andrew Newell 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에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by