Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to create a plot style with a table and manipulate the variables in the plot style.

Menge = {g, h};
Manipulate[
  Plot[{0.5 x + 1, x}, {x, -1, 5},
    PlotStyle -> Table[Opacity[Menge[[i]]], {i, 1, Length[Menge]}]],
{g, {1, 0}}, 
{h, {1, 0}}]

This code won't work. But when i create the table and simply copy the output it works.
Can someone help me out?

share|improve this question
    
ah sorry. i mixed up the variables. That's just a small example. I justs want the PlotStyle to be generated from a set like Menge. The arguments for the Manipulate should also be generated from Menge. This i have already working, but i'm struggling with the plotstyle. –  user11004 Dec 7 '13 at 9:18
1  
g inside Manipulate is not the same as the one in Menge. Manipulate is scoping h ang g. Try adding Initialization :> (Menge = {g, h};) to the manipulate. –  Kuba Dec 7 '13 at 9:26

3 Answers 3

Is this what you are looking for?

Edit: Menge outside as OP wants.

Menge := {g, h};
Manipulate[
 Dynamic@Plot[{0.5 x + 1, x}, {x, -1, 5}, PlotStyle -> Opacity /@ Menge],
 {g, {1, 0}}, {h, {1, 0}}, 
 LocalizeVariables -> False]
share|improve this answer
    
nearly. I want the Elements of Menge to come from "outside" of the manipulate. In my sheet Menge is a quite big set which is generated dynamically. The arguments for the Manipulate i generate with $Evaluate@(Sequence @@ Table[{Menge[[i]], {1, 0}}, {i, 1, Length[Menge]}])$ and now i also want to generate the PlotStyle dynamically to show and hide my plotted functions which i generated earlier. –  user11004 Dec 7 '13 at 9:38
    
@user11004 Ok, so you can use LocalizeVariables->False or,what I strongly recommend, use DynamicModule to have full control what is important for bigger projects. –  Kuba Dec 7 '13 at 9:41
    
Thank you! LocalizeVariables solved my problem. But i will have a look at DynamicModule! Thanks for your patience! –  user11004 Dec 7 '13 at 9:44

I really don't see the value of having a list of opacity control variables external to the Manipulate expression. Were you to change the external list, you would still have to edit the Manipulate to add or remove slider controls to support your changes. So why not just do it all in the Manipulate expression?

Manipulate[
  Dynamic @ Plot[{0.5 x + 1, x}, {x, -1, 5}, PlotStyle -> Opacity /@ vars],
  {{op1, 1, "g-opacity"}, 0, 1, .1, Appearance -> "Labeled"},
  {{op2, 1, "h-opacity"}, 0, 1, .1, Appearance -> "Labeled"},
  {vars, ControlType -> None},
  Initialization :> (vars := {op1, op2})]

plot.png

share|improve this answer

If you want Menge to be global then the minimum alteration to what you have done to get this to work would be this:

Manipulate[
 Dynamic@Plot[{0.5 x + 1, x}, {x, -1, 5},
   PlotStyle -> Opacity /@ Menge[g, h]],
 {{g, 1}, 0, 1},
 {{h, 1}, 0, 1},
 Initialization :> {Menge[g_, h_] := {g, h}}]

enter image description here

I always would recommend that you have your external function(s) within Initialization. From there you can add other things to make it look pretty.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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