Hi Ishaan,
The code you provided uses data coordinates to specify the position of the text arrow. This means that the arrow will move and resize when you zoom in and out of the figure.
To fix this and have the text arrow maintain a locked position (head fixed) with the tail resizing based on the zoom level, you can use normalized units instead. Here's the modified code:
% Red labelled rectangle highlighting the area of interest
rectangle('position', [0.7 0.2 0.1 0.1], 'edgecolor', 'r');
text(0.69, 0.18, 'Area of Interest', 'Color', 'red', 'FontSize', 10, 'FontWeight', 'bold');
% Head position (fixed in normalized units)
xh = 0.8;
yh = 0.3;
% Tail position (adjustable based on data coordinates)
xt = 0.75;
yt = -0.1;
% Create text arrow with normalized units and adjustable tail
annotation('textarrow', [xt xh], [yt yh], 'String', 'Panaitan Island', 'Units', 'normalized');
Here,
- Normalized Units: The "Units", "normalized" argument is added to the "textarrow" annotation. This ensures the arrow position is specified relative to the figure window, keeping it fixed during zoom.
- Head position: The head coordinates ("xh" and "yh") are set as fixed values between 0 and 1 (normalized units).
- Tail position: The tail coordinates ("xt" and "yt") are defined using data coordinates. You can adjust these values based on your data to position the tail appropriately.
This approach will keep the text arrow's head fixed while the tail resizes based on the data coordinates and zoom level. Heres a link to MathWorks documentation that demonstrates the same in an example: https://in.mathworks.com/help/matlab/ref/annotation.html