I have an interactive plot in a Manipulate
expression with a PopupMenu
. I want to be able to select the function being plotted with the popup. When I use the PopupMenu the other controls (sliders) stop working. I am unable to find the problem.
Manipulate[
Plot[f[x], {x, -10, 10}, PlotRange -> {-10, 10}],
{f, {a # + b & -> "Linear", Abs [a # + b] & -> "Absolute Value"},
ControlType -> PopupMenu},
{a, -3, 3, 1, Appearance -> "Labeled"},
{{b, -5, "y-intercept"}, 5, 1, Appearance -> "Labeled"}]
I have seen several examples for PopupMenu
and SetterBar
. But none where parameters in a dynamically selected function can be changed by other controls.
Plot
command does what I think you want.Manipulate[ Plot[f[x] /. {a -> $a, b -> $b}, {x, -10, 10}, PlotRange -> {-10, 10}], {f, {a # + b & -> "Linear", Abs[a # + b] & -> "Absolute Value"}, ControlType -> PopupMenu}, {$a, -3, 3, 1, Appearance -> "Labeled"}, {{$b, -5, "y-intercept"}, 5, 1, Appearance -> "Labeled"}]
$\endgroup$Manipulate[ Dynamic@Plot[f[x], {x, -10, 10}, PlotRange -> {-10, 10}], {f, {a # + b & -> "Linear", Abs[a # + b] & -> "Absolute Value"}, ControlType -> PopupMenu}, {a, -3, 3, 1, Appearance -> "Labeled"}, {{b, -5, "y-intercept"}, -5, 5, 1, Appearance -> "Labeled"}]
. The plot needs to be dynamic in order to be updated in this fashion. If I come up with a good explanation why, I'll post an answer rather than a comment. $\endgroup$