Effacer les filtres
Effacer les filtres

Normalize axis scale for annotations

11 vues (au cours des 30 derniers jours)
HC98
HC98 le 28 Fév 2024
Commenté : Dyuman Joshi le 29 Fév 2024
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 commentaire
Dyuman Joshi
Dyuman Joshi le 29 Fév 2024
You can use rescale on the values and then provide them as input to annotation().

Connectez-vous pour commenter.

Réponse acceptée

Austin M. Weber
Austin M. Weber le 28 Fév 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.

Plus de réponses (0)

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by