필터 지우기
필터 지우기

How do I use Latex formatting in graph node labels?

조회 수: 2 (최근 30일)
Harry Smith
Harry Smith 2016년 6월 14일
편집: Rub Ron 2023년 3월 23일
For example, I have the following snippet:
A = [0 1 1; 1 0 0; 1 0 0];
names = {'V', texlabel('mu'), 'Q'};
params = graph(A, names);
h = plot(params);
And it yields a graph with a node labelled '{\mu}'. How can I get that to display as a µ character? I've tried setting the default interpreter of the figure to Latex and I've played with the formatting of the string. Thanks.

답변 (4개)

KL
KL 2016년 6월 14일
Hello,
Replacing 'mu' with '{\mu}' should do the trick. Nevertheless here is a popular link which eases your plot generation for latex
Hope it helps.
  댓글 수: 2
Harry Smith
Harry Smith 2016년 6월 15일
Thank you for the response! Unfortunately, that's not fixing it for me. Do you have any other suggestions? Are you able to take my code and produce Latex'd labels using the suggestion you provided me?
Thanks, Harry
KL
KL 2016년 6월 16일
bar(1:5)
set(gca,'XTickLabel',{'{\mu}','fgh','10','{\pi}','{\sigma}'})
like this? if you wanna store greek symbols in cell array you need to know the respective ascii code and then use char(ascii_code)

댓글을 달려면 로그인하십시오.


Jules BROCHARD
Jules BROCHARD 2017년 5월 26일
Hey, Did you find a way to do it ? I would really appreciate if you could share it with me :)

ABIYA R
ABIYA R 2019년 11월 16일
names = {'V', '\mu', 'Q'}; and changing 'tex' to 'latex' in the Figure properties editor solved the problem for me.

Rub Ron
Rub Ron 2023년 3월 23일
편집: Rub Ron 2023년 3월 23일
I have faced the same issue. This is a work around:
% you may need this before executing the code
set(groot,'DefaultTextInterpreter','latex')
set(groot, 'defaultLegendInterpreter','latex');
set(groot, 'defaultAxesTickLabelInterpreter','latex');
%plotting graph
A = [0 1 1; 1 0 0; 1 0 0];
names = {'V', '$\mu$', 'Q'}; % use $$ for the interpreter to read it as a equation
params = graph(A, names);
figure
h = plot(params);
h.NodeLabel = {}; %remove default labels
%creating labels as text
x_offset=0.05;
y_offset=-0.05;
text(h.XData+x_offset, h.YData+y_offset,names, ...
'VerticalAlignment','Bottom',...
'HorizontalAlignment', 'left')

카테고리

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