2
$\begingroup$

I was trying to change the position and distance from the plot of a label generated using Callout. The following code specifies different LeaderSize for the Callout, but there is no difference in the resulting plots:

Row[
  Plot[
    Callout[Sin[x], "sin(x)", Scaled[1/4], LeaderSize -> #],
    {x, 0, 2 Pi}, ImageSize -> Small
  ] & /@ {5, 15, 50}
]

three plots with the identical labels and no difference in callout leader size

$\endgroup$

1 Answer 1

4
$\begingroup$

The closest previous question I found is How to change Callout leader size in Plot? but the answers did not contain what I think may be the key issue. It took me a while to figure out what I was doing wrong and I got pretty frustrated in the process, so I thought I'd share the solution I found here.

The Callout syntax: Callout[data, expr, pos, apos] specifies that the callout label expr is to be located at position pos, and the callout anchor (i.e. the point on the plot where the callout leader "starts") at position apos.

I had thought that, if I specify a position pos for the label, and a size or other properties of the leader with LeaderSize, then the position of the callout anchor would be adjusted automatically. However, this is not true. If the position of the label is specified, then most specifications in LeaderSize are quietly ignored, as shown above in the question. This was very counter-intuitive to me. [To be fair, not all LeaderSize settings are ignored: some angles and distances from the plot are respected, but the length of the leader itself is not.]

It turns out that, to change the size of the callout leader, the callout label itself needs to be free to move around, so it should be set to Automatic. The position of the label anchor should be set instead. The system then adjusts the position of the label to comply with the properties requested with LeaderSize.

In short, I needed: Callout[data, label, Automatic, position], as in the following amended code:

Row[
  Plot[
    Callout[Sin[x], "sin(x)", Automatic, Scaled[1/4], LeaderSize -> #],
    {x, 0, 2 Pi}, ImageSize -> Small
  ] & /@ {5, 15, 50}
]

callout leaders are now of different lengths in the three plots

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.