MATLAB: How to ensure that the arrows in the plot stay at the same data point when I zoom in MATLAB 7.14 (R2012a)

MATLAB

I have some data that I plot using the PLOT command. I want to draw some arrows of a given length on top of the plot at some coordinates given by the data. I want to plot the arrows in such a way that when I zoom in the plot the arrows maintain their position with respect to the data. I have been using the command ANNOTATION to create the arrows specifying the initial and final point for the arrow. However, when zooming in, the arrows appear at the same point relative to the figure but they move relative to the data. How can I avoid this behaviour?

Best Answer

The ANNOTATION function creates an arrow that extends from the point defined by x(1), y(1) to the point defined by x(2), y(2) when calling it in the following way:
annotation('arrow', x, y)
The two points 'x' and 'y' that define the arrow are specified in normalized figure units. This means that when zooming into the plot the arrows will stay at the same position relative to the figure, but will have moved relative to the plot.
Plotting several arrows on particular locations given by the data instead of the figure can be achieved with the QUIVER function. The following code:
quiver(x, y, u, v)
plots the vector (u, v) as an arrow with starting points defined by the coordinates (x, y). These coordinates refer to the data coordinates and not to the figure. Moreover, QUIVER gives the option to plot multiple arrows at the same time as the variables 'x', 'y', 'u' and 'v' can be defined as arrays. The only prerequisite is that they must have the same dimension. As QUIVER plots arrows at particular locations given by the 'x' and 'y' coordinates, when the figure is zoomed in, the arrows maintain their initial point at the same coordinate and they do not move relative to the plot.
Related Question