How do I use Latex formatting in graph node labels?

11 views (last 30 days)
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.

Answers (4)

KL on 14 Jun 2016
Replacing 'mu' with '{\mu}' should do the trick. Nevertheless here is a popular link which eases your plot generation for latex
Hope it helps.
KL on 16 Jun 2016
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)

Sign in to comment.

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

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

Rub Ron
Rub Ron on 23 Mar 2023
Edited: Rub Ron on 23 Mar 2023
I have faced the same issue. This is a work around:
% you may need this before executing the code
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);
h = plot(params);
h.NodeLabel = {}; %remove default labels
%creating labels as text
text(h.XData+x_offset, h.YData+y_offset,names, ...
'HorizontalAlignment', 'left')


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!