Adding labels to plots with LaTeX syntax
7 次查看(过去 30 天)
显示 更早的评论
I was wanting to do something like this
But I'm not sure
0 个评论
回答(2 个)
Anton Kogios
2023-9-18
plot(0:.1:pi,sin(0:.1:pi))
text(pi/2,.9,'$$t = \frac{\pi}{2}$$', ...
'Interpreter','latex', ...
'FontSize',14, ...
'HorizontalAlignment','center')
0 个评论
Star Strider
2023-9-18
In the text call, specify 'Interpreter','latex', however the more interesting part of this was (finally) figuring out how to correctly place the annotation objects.
This combines both of them —
x = linspace(-2, 1, 250);
y = 3.5*exp(-(x+1).^2*150);
figure
plot(x, y, '--k')
ylim([-1 4])
yline(0, '-k')
text(0, 3.5, '$\it{t=0}$', 'Interpreter','latex', 'FontSize',15, 'Horiz','center')
text(-1.5, 1.75,'$\alpha\_$', 'Interpreter','latex', 'FontSize',15, 'Horiz','center')
xs = @(x,pos,xlim) pos(3)*(x-min(xl))/diff(xl)+pos(1);
ys = @(y,pos,ylim) pos(4)*(y-min(yl))/diff(yl)+pos(2);
xl = xlim;
yl = ylim;
pos = gca().Position;
xs = @(x,pos,xlim) pos(3)*(x-min(xl))/diff(xl)+pos(1); % 'x' Annotation Position Function
ys = @(y,pos,ylim) pos(4)*(y-min(yl))/diff(yl)+pos(2); % 'y' Annotation Position Function
% Qy = ys([2.5 3.5],pos,ylim)
% Qx = xs([1 1]*-1.5,pos,xlim)
annotation('arrow', xs([-1.5 -1.5],pos,xlim), ys([1.5 0],pos,ylim))
annotation('arrow', xs([-1.5 -1.5],pos,xlim), ys([2.0 3.5],pos,ylim))
I am not certain what the other curves represent, so I did not draw them.
.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Formatting and Annotation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!