0
$\begingroup$

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.

$\endgroup$

1 Answer 1

1
$\begingroup$

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}]
$\endgroup$
1
  • $\begingroup$ Would using a delayed assignment with args outside Manipulate accomplish the same thing? I thought I had tried that, but perhaps not. $\endgroup$
    – mnosefish
    Commented Apr 15, 2021 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.