How can I use Callout to label the segments of a piecewise function?
Clear["Global`*"]
h[x_] := Piecewise[{{Exp[x],
x < -1}, {1 - x^2, -1 < x < 1}, {Sin[Pi x], x > 1}}];
plotRng = {-3, 3};
EDIT: Extracting intervals
intervals = {Cases[h[x][[1, All, -1]], _?NumericQ, 2], plotRng} //
Flatten // Union // Partition[#, 2, 1] &;
Show[
Plot[
Callout[h[x],
Simplify[h[x], Less @@ Insert[#, x, 2]] //
TraditionalForm // ToString,
Above,
Appearance -> None,
Background -> None],
{x, Sequence @@ #},
PlotStyle -> Red] & /@
intervals,
PlotRange -> {plotRng, Automatic}]
It is possible to nest several Callout
:
ClearAll[x, h];
h[x_] := Piecewise[{{Exp[x],
x < -1}, {1 - x^2, -1 < x < 1}, {Sin[Pi x], x > 1}}];
Plot[
Callout[Callout[Callout[h[x], "Exp[x]", -2], "Sin[Pi x]", 2],
"1-x^2", {0.3, Above}], {x, -3, 3}]
Seen in this video of Wolfram Technology Conference 2018.
There is a notebook attached to this video - see Section "parametric Curve Labeling"