Using time derivative dot in plot legend

195 views (last 30 days)
Simon
Simon on 25 Nov 2014
Hello! I would like to use the time derivative dot over a character in my legend to a plot. I have searched and no solution seems to work.
This is what i would like to do (if it where latex) \dot{\theta}_{in}
Any suggestions? Using Matlab R2014A

Answers (3)

Kelly Kearney
Kelly Kearney on 25 Nov 2014
You just need to set the interpreter after plotting:
plot(rand(10,1));
hl = legend('$\dot{\theta}_{in}$');
set(hl, 'Interpreter', 'latex');
It'll issue a warning when you first plot the legend, since it tries to use the tex renderer, but you can just ignore that.

Geoff Hayes
Geoff Hayes on 25 Nov 2014
Simon - you could set the legend string using the LaTeX "code", and then change the Interpreter property of the legend to latex so that the string is interpreted appropriately. For example,
close all;
x = linspace(-2*pi,2*pi,1000);
y = sin(x);
plot(x,y);
hLeg = legend('$$sin(\theta)$$');
set(hLeg,'Interpreter','latex');
The above will plot the sine curve and display the legend text formatted as per the LaTeX string.
In your case, your legend string would be set as
hLeg = legend('$$\dot{\theta}_{in}$$');
Try the above and see what happens! (Note that the above was tested on R2014a, OS X 10.8.5.)

Andreas Wagner
Andreas Wagner on 15 Aug 2018
Hi!
I also use this solution, but I would like to have the latex interpreted entries in the same font, like I didn't use the Latex interpreter. Further I have a problem, if more than one legend entry with dot. As well in the same legend I have entries which shouldn't be interpreted by 'latex':
leg=legend({'{\it \vartheta}_{W2,aus,Na.}','{\it \vartheta}_{W2,aus,ÜK}','{\it \vartheta}_{V11,ein,Na}','{\it \vartheta}_{V11,ein,ÜK}',... '$\dot{\it m}_{Sammler,aus,Na}$','$\dot{\it m}_{Sammler,aus,ÜK}$'},... 'location','northeast','fontsize',fontsizelegend); set(leg,'Interpreter','latex')
What do I have to do to create legend with the same font for all entries incuding "dot entries"?
Kind regards
Andreas Wagner
  1 Comment
Pa342
Pa342 on 28 Sep 2018
It isn't possible and generally all the "work arounds" don't really quite work as intended. You can try putting \textsf{} around the letters e.g. legend('$\textsf{test}$') but it isn't quite correct.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!