3
votes

When doing multiple plots on the same figure in MATLAB, is there any way of annotating them such that the legend entries have arrows pointing to the plots that they're named for?

Here's an example of what I have in mind. I'd like to do this using code.

enter image description here

Note that the MATLAB website mentions a way to do this using the annotation function. The problem with that function is that it takes x and y values (normalized for the plot) and puts the text there. Given that I am not certain where the datapoints will lie, this is unhelpful for what I want to do.

I don't mind if the text shows up at a random place, actually. What's important is to have an arrow or some way of pointing to the plot that it is referencing.

1
So you want to create an arrow that points at a location which is unknown to you? - Eitan T
Location isn't really important. It's that the arrow points somewhere in the plot that it is referencing that matters. - eqb
(For example, in the picture that I have attached, the vapor pressure fit could have pointed anywhere on the red line.) - eqb
This is a good question +1. You're essentially asking how to find the location within a figure of a line that you've plotted. Unfortunately the line object contains the x and y data-points used to form the line, but not the location of those points within the borders of the figure. You might be able to infer the locations by obtaining the position of the axes within the figure (see Position property of Axes object), and then inferring the location of the x and y data points by comparing them to the axes labels - but this feels very messy... - Colin T Bowers
Yes, I think you've described precisely what I'm looking for. I'll look at conversion to normalized units. Thanks for your help! - eqb

1 Answers

3
votes

Take a look at the following Math works file exchange post:

http://www.mathworks.co.uk/matlabcentral/fileexchange/10656-data-space-to-figure-units-conversion

The code given here allows you to convert between data-space units and normalised figure units. The example given in the post seems to be doing almost exactly what you are asking.