Borrar filtros
Borrar filtros

Normalize axis scale for annotations

8 visualizaciones (últimos 30 días)
HC98
HC98 el 28 de Feb. de 2024
Comentada: Dyuman Joshi el 29 de Feb. de 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 comentario
Dyuman Joshi
Dyuman Joshi el 29 de Feb. de 2024
You can use rescale on the values and then provide them as input to annotation().

Iniciar sesión para comentar.

Respuesta aceptada

Austin M. Weber
Austin M. Weber el 28 de Feb. de 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.

Más respuestas (0)

Categorías

Más información sobre Labels and Annotations en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by