필터 지우기
필터 지우기

Normalize axis scale for annotations

조회 수: 9 (최근 30일)
HC98
HC98 2024년 2월 28일
댓글: Dyuman Joshi 2024년 2월 29일
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
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2024년 2월 29일
You can use rescale on the values and then provide them as input to annotation().

댓글을 달려면 로그인하십시오.

채택된 답변

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