When I plot a Piecewise
function, I like to put the function name above each part of the plot. I could not find a way to use Callout
. So now I use Text
to manually put the function name above each part of the curve. Here is MWE
ClearAll[x,h];
h[x_] := Piecewise[{{Exp[x],x < -1}, {1 - x^2, -1 < x < 1}, {Sin[Pi x], x > 1}}];
Plot[h[x], {x, -3, 3}]
Obviously, putting the Callout
inside Piecewise
does not work.
h[x_] :=
Piecewise[
{{Callout[Exp[x], "Exp[x]"], x < -1},
{1 - x^2, -1 < x < 1},
{Sin[Pi x], x > 1}}];
So now I do the following, which requires few trials and errors to get the labels in the right place.
h[x_] := Piecewise[{{Sin[Pi x],x > 1}, {1 - x^2, -1 < x < 1}, {Exp[x], x < -1}}];
Plot[h[x], {x, -3, 3},
PlotRange -> {Automatic, {-1.2, 1.2}},
PlotStyle -> Red,
BaseStyle -> 12,
Epilog ->
{Text["Exp[x]", {-2, .3}],
Text["1-x^2", {.4, 1.1}],
Text["Sin[Pi x]", {1.7, .3}]}]
My question is: Is there a trick to use Callout
when plotting Piecewise
function?
V 12 on windows