0

I'm trying to create a table of diagrams of which each shows a different variable on the x axis and fetches the remaining parameters from the enclosing scope, a Manipulate object.

So I have this code that creates the expression to be plotted for each plot.

f[a_, b_, c_] := a + b + c
args = {{x, b, c}, {a, x, c}, {a, b, x}}
Manipulate[
 Evaluate[f @@ # & /@ args],
 {a, 0, 1}, {b, 0, 1}, {c, 0, 1}
 ]

Expression generator working as planned

But then when I go to plot it, it appears to evaluate the expression correctly within the Manipulate scope but not the Plot scope

Manipulate[
 Evaluate[Plot[Evaluate[f @@ #], {x, 0, 1}, PlotLabel -> f @@ #] & /@ args],
 {a, 0, 1}, {b, 0, 1}, {c, 0, 1}
 ]

Plot generator not working as planned

I found this post which seems to do what I want, but I can't seem to figure out the idiom behind it or how it differs from my approach. I'm sure this is a scoping issue, but I've tried changing things at pretty much each stage of evaluation, and this seemed closest to being correct in terms of results. Just as much as solving the problem, I'd like to know why this particular implementation isn't working.

mnosefish
  • 115
  • 3

1 Answers1

1

args needs to be scoped within the Manipulate.

Manipulate[
 args = {{x, b, c}, {a, x, c}, {a, b, x}};
 Plot[Evaluate[f @@ #], {x, 0, 1}, PlotLabel -> f @@ #] & /@ args, {a, 0, 1}, {b, 0, 1}, {c, 0, 1}]
Rohit Namjoshi
  • 10,212
  • 6
  • 16
  • 67
  • Would using a delayed assignment with args outside Manipulate accomplish the same thing? I thought I had tried that, but perhaps not. – mnosefish Apr 15 '21 at 17:58