Normalize axis scale for annotations

6 visualizzazioni (ultimi 30 giorni)
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 Commento
Dyuman Joshi
Dyuman Joshi il 29 Feb 2024
You can use rescale on the values and then provide them as input to annotation().

Accedi per commentare.

Risposta accettata

Austin M. Weber
Austin M. Weber il 28 Feb 2024
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.

Più risposte (0)

Categorie

Scopri di più su Labels and Annotations in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by