Using time derivative dot in plot legend

68 次查看(过去 30 天)
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

回答(3 个)

Kelly Kearney
Kelly Kearney 2014-11-25
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 2014-11-25
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 2018-8-15
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 个评论
Pa342
Pa342 2018-9-28
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.

请先登录,再进行评论。

类别

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