# Manipulate a parameter within the PlotLabel

Very similar to

Parameters in plot titles

in which I want to call a parameter from an array using PlotLabel in my plot using Manipulate. I've tried all of the suggestions in the above post and keep getting the same error. Simple code:

f = {1, 2, 3, 4, 5, 6};
Manipulate[
Plot[Sin[f[[g]] x], {x, -2, 2}, PlotLabel -> Text["f =" f[[g]]]], {g,
1, 3, 1}] Curiously, the first f value does not show up incorrectly to the left of the "f=" string. Instead of Text[] I've also tried HoldForm[], TraditionalForm[], Defer[]. I'm not too picky on where "f =" shows up, but this is pretty confusing to me as why this doesn't work as it should. Thanks

• f = {1, 2, 3, 4, 5, 6}; Manipulate[ Plot[Sin[f[[g]] x], {x, -2, 2}, PlotLabel -> Row[{"f = ", f[[g]]}]], {{g, 1, "index"}, 1, Length[f], 1, Appearance -> "Labeled"} ] – Nasser Sep 16 '14 at 23:44

What you observe is simply because you use a multiplication without noticing it. Basic example:

"f=" 2

(* 2 "f=" *)


If you look at the full form of this output with FullForm[%] you see that it is indeed Times[2, "f="]. Because the terms in a multiplication are re-ordered by Mathematica, you get the wrong result.

The solution is to either use Row like shown by Nasser in the comment

f = {1, 2, 3, 4, 5, 6};
Manipulate[
Plot[Sin[f[[g]] x], {x, -2, 2},
PlotLabel -> Row[{"f = ", f[[g]]}]],  {{g, 1, "index"}, 1, 3, 1,
Appearance -> "Labeled"}
]


or you create a full string from your content with

Text["f = " <> ToString[f[[g]]]]]


Just another way using v10 StringTemplate

Manipulate[
Plot[Sin[f[[g]] x], {x, -2, 2},
PlotLabel -> TemplateApply[s, g]], {g, Range},
Initialization :> (f = Range;
s = StringTemplate["f=<*f[]*>"])] If you prefer the traditional form of expressions rather than the version in graphics one way (there are almost certainly better):

Manipulate[
With[{lab =
st = StringTemplate["f=<*f[]*>", CombinerFunction -> RowBox])] 