Manipulate[
Plot[
a*x + b, {x, -10, 10},
PlotRange -> {{-10, 10}, {-10, 10}},
PlotLabel -> Row@{"Linear function", a*x + b}],
{{a, 1}, -5, 5}, {{b, 0}, -5, 5}]
Works nice. But I'd like to modify the label a little, so that it shows the formula with parameters a
and b
literaly stated, rather then converted to their values. I've been trying to achieve that this way:
Manipulate[
holdedf = a*x + b // HoldForm;
f = holdedf // ReleaseHold;
Plot[
f, {x, -10, 10},
PlotRange -> {{-10, 10}, {-10, 10}},
PlotLabel -> Row@{"Linear function", holdedf}],
{{a, 1}, -5, 5}, {{b, 0}, -5, 5},
TrackedSymbols :> {a, b}]
Yes, I know this code doesn't look very pretty... But the idea was to avoid writing the formula twice: once in the Plot
, and once as the PlotLabel
.
But this doesn't work as expected. The Plot
shows nicely, but the label is distorted. It looks like that: Linear functionFE`a$$156 x + FE`b$$156
Same results if I resing from definining holdedf
:
Manipulate[
Plot[
a*x + b, {x, -10, 10}, PlotRange -> {{-10, 10}, {-10, 10}},
PlotLabel -> Row@{"Linear function", a*x + b // HoldForm}],
{{a, 1}, -5, 5}, {{b, 0}, -5, 5}]
And one final example. Evaluate
should cancel HoldForm
, right? So I can't understand this:
Manipulate[
Plot[
a*x + b, {x, -10, 10}, PlotRange -> {{-10, 10}, {-10, 10}},
PlotLabel -> Row@{"Linear function", (Evaluate@a)*x + (Evaluate@b) // HoldForm}],
{{a, 1}, -5, 5}, {{b, 0}, -5, 5}]
The Evaluate
doesn't seem to cancel HoldForm
; instead, the label it looks like this: LinearFunctionEvaluate[FE`a$$173] x + Evaluate[FE`b$$173]
Why does this happen? Can it be fixed, or do I have to resort to PlotLabel->"Linear function a x + b"
? Is there any better approach to what I'm trying to achieve?