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!