5
$\begingroup$

Take this example:

Plot[Callout[Sin[x], Sin[x], Above], {x, 0, Pi}]

Mathematica graphics

Question: How can I change the length of the line connecting the $\sin(x)$ label with the plotted curve?

I believe this line is called the "leader" and it can be modified with the LeaderSize option. But adding either LeaderSize -> 10 or LeaderSize -> {10} to Callout makes no difference.

Motivation: When the plot has a wide aspect ratio, the leaders tend to be too long. I assume this is because they are computed relative to the figure width.

Plot[Callout[Sin[x], Sin[x], Above], {x, 0, Pi}, AspectRatio -> 1/4]

Mathematica graphics

$\endgroup$
1
  • 1
    $\begingroup$ i don't know why but it seems that the both the leader and the neck change only if you set the position to Automatic : Plot[Callout[Sin[x], Sin[x], Automatic, LeaderSize -> {{70, 0, 0}, {10, 0, 0}}], {x, 0, Pi}, AspectRatio -> 1/4] $\endgroup$
    – Alucard
    Sep 3, 2017 at 14:55

5 Answers 5

2
$\begingroup$

Here is a workaround (besides the obvious one of specifying an explicit coordinate instead of Above) where I shrink the neck size:

Plot[
    Callout[
        Sin[x],
        Rotate[Sin[x], -Pi/2],
        Above,
        FrameMargins -> 0,
        LeaderSize -> {Automatic, {0, Pi/2}}
    ],
    {x, 0, Pi},
    AspectRatio -> 1/4
]

enter image description here

Another possibility is to bend the callout:

Plot[
    Callout[
        Sin[x],
        Sin[x],
        Above,
        LeaderSize -> {Automatic, {0, Pi/4}}
    ],
    {x, 0, Pi},
    AspectRatio -> 1/4
]

enter image description here

$\endgroup$
2
$\begingroup$

maybe help:

Table[Plot[
  Callout[Sin[x], Sin[x], Above, 
   LeaderSize -> {100, 90 \[Degree], i}], {x, 0, Pi}, 
  PlotRange -> Full], {i, 0, 30, 5}]

enter image description here

or

Manipulate[
 Plot[Callout[Sin[x], "Sin[x]", {Pi/2, a}, Pi/2], {x, 0, Pi}, 
  PlotRange -> {Automatic, {0, 2}}], {a, 1.1, 1.75}]
$\endgroup$
3
  • 1
    $\begingroup$ Please add a plot demonstrating the effect of your code. $\endgroup$
    – bbgodfrey
    Sep 3, 2017 at 14:42
  • $\begingroup$ @bbgodfrey I have re-edited the answer $\endgroup$ Sep 3, 2017 at 15:14
  • 1
    $\begingroup$ Somehow I was hoping for an answer where the label did go further away from the curve, instead of the gap doing so. $\endgroup$ Sep 3, 2017 at 15:32
1
$\begingroup$

Consider specifying position for the callout {pos, epos}

enter image description here

Plot[Callout[Sin[x], "Sin(x)", {N@\[Pi]/2, 2.}, 
CalloutMarker -> "\[EmptyCircle]", CalloutStyle -> Gray], {x, 0, 
Pi}, PlotRange -> {{0, 3}, {0, 3}}]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Here you are explicitly specifying the callout position. LeaderSize has no effect Can you point this out in the answer, and remove the superfluous LeaderSize option (since it does nothing here)? $\endgroup$
    – Szabolcs
    Sep 4, 2017 at 8:21
1
$\begingroup$

Using different neck lengths:

 Plot[Callout[Sin[x], Rotate[Sin[x],- 90 Degree], Above, 
   LeaderSize -> {{100, 90 Degree, 0}, {#, 90 Degree}}], {x, 0, Pi}, 
  PlotRange -> Full, ImagePadding->50, ImageSize-> 300] &/@ {0, 30, 70}// Row

enter image description here

$\endgroup$
1
$\begingroup$

It appears that, once the position of the callout label is set (e.g. with Above), the length of the leader is ignored. Instead, one has to let the position of the label be calculated automatically (i.e. Automatic) and specify the position of the anchor instead:

Plot[
  Callout[
    Sin[x], Sin[x], Automatic, Scaled[0.3], 
    LeaderSize -> {{15, 90 Degree, 3}, {10, 180 Degree}}
  ],
  {x, 0, Pi}, AspectRatio -> 0.2
]

Unfortunately, symbolic positions such as Above are not available for the callout anchor position, so an explicit position is needed; Scaled coordinates work best for me here.

I ran into similar trouble recently, which is what led me to your question. The solution I propose above is discussed in more detail here: LeaderSize has no effect on Callout in Plot.

$\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.