Normalize axis scale for annotations

8 次查看(过去 30 天)
I want to label a simple plot for some notes:
hf = figure;
x = -180:180;
f = @(x) 0.09*sech(-x/18);
plot(x, f(x));
ha = annotation('arrow');
ha.Parent = hf.CurrentAxes; % associate annotation with current axes
% now you can use data units
ha.Y = [50 20];
ha.X = [f(20) f(20)];
annotation("doublearrow", [0.45 0.45], [0.1 1]);
The trouble is, I want to use the coordinates from the plot, not the "normalized" figure coordinates. How can I rescale them so that
annotation("doublearrow", [0.45 0.45], [0.1 1]);
becomes
annotation("doublearrow", [0 0], [0 1]);
Thanks

采纳的回答

Austin M. Weber
Austin M. Weber 2024-2-28
The text function allows you to place annotations on a figure using axes coordinates. For example:
hf = figure;
x = -180:180;
f = @(x) 0.09*sech(-x/18);
plot(x, f(x));
ha = annotation('arrow');
ha.Parent = hf.CurrentAxes; % associate annotation with current axes
% now you can use data units
ha.Y = [50 20];
ha.X = [f(20) f(20)];
% Add annotations
hold on
text(0,0.08,'⇑','FontSize',20,...
'HorizontalAlignment','center') % Other double arrows: ⇐ ⇑ ⇒ ⇓
hold off
I'm sure there is a way that you can use the annotation function to do what you want, but I think this method might be easier. I would have to play around with annotation to see how it might work.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Labels and Annotations 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by