MATLAB: How to pin annotations (or text) to a graph below the x-axis

annotation;arrowfigurelineplottext arrowtext boxtext;

I would like to add vertical lines (or arrows) and text-labels below the x-axis at particular x-axis-values in my plots. Here is an example-plot:
I would like to draw vertical lines or arrows downwards from the x-axis exactly where the white lines are in the graph (basically 'extending' the white lines below the x-axis). At the bottom end of those lines/arrows I would like to add labels ('LHS', 'RTO', 'RHS', 'RTO'; as shown in graph). How can I do that?
My current solution is to use text instead of annotation (as shown in graph) because it allows me to add the labels below the x-axis (see part of my script below). However, this way I cannot add lines/arrows with the labels and when resizing the image the labels are moving in y-direction (they seem to have a relative position rather than being pinned to an absolute value in the graph?). Thus, I would like to improve my current solution. I am looking for a programmatic solution, not interactive.
One problem with using annotation seems to be that one is required to give the coordinates in normalised units, which, in turn, does not allow me to add objects like lines/arrows/textboxes below the x-axis. I have tried to convert the units, and to use other units like pixels or centimeters but I could not get it to work (but maybe I am doing something wrong). Another problem is to pin the annotation to the axes data. I have been reading through Yair Altman's undocumented matlab site on this topic as well as checked other answers here and in other forums but I cannot quite work out how to adjust these suggestions for my particular problem.
This is a snapshot of my code that creates the figure:
figure
imagesc(T, F, P(:,:,3))
set(gca,'ylim', [0 60],'ydir','normal')
hold on
plot([0 0],get(gca,'ylim'),'w:') % draw vertical line at RHS
text(0,-3,'RHS')
plot([x_RTO x_RTO],get(gca,'ylim'),'w:') % draw line at RTO
text(x_RTO,-3,'RTO')
plot([x_LHS x_LHS],get(gca,'ylim'),'w:') % draw line at LHS
text(x_LHS,-3,'LHS')
plot([x_LTO x_LTO],get(gca,'ylim'),'w:') % draw line at LTO
text(x_LTO,-3,'LTO')
xlabel('time [s]')
ylabel('frequency [Hz]')
colorbar
In this example, T is a 41×1 double (listing values from -0.8 to 0.2), F is a 1025×1 double (listing values from 0 to 1000), and P(:,:,3) is a 1025×41 double; x_RTO = -0.4675; x_LHS = -0.5919; x_LTO = 0.1353.
Many thanks for your help!

Best Answer

You can use the ‘\uparrow’ text character to plot the arrows. It may not be quite the result you want, but it’s likely the only option you have.
For example:
d = rand(20);
figure(1)
imagesc(d)
text(5, 22, sprintf('\\uparrow\nLTO'), 'HorizontalAlignment','center', 'FontWeight','bold')
Related Question