How can I add a Plot or Plot3D to my DynamicModule (on the same panel) without having a negative impact on the original function? I tried different (for me) logical ways to add the Plot function, but I can't seem to get it work.

DynamicModule[{a, asq},
  a = 0;
  asq[]:= a*a;
            {{Style["Input number", Blue], Style["Square of number",Red]},
             {InputField[Dynamic[a], Number], 
              InputField[Dynamic[asq[]], Enabled -> False,Background ->Red]}}],
          Alignment -> Left],
          ImageMargins -> 10], 
      DefaultOptions -> 
       {InputField -> {ContinuousAction -> True, FieldSize -> {{5,30}, {1, Infinity}}}}]]]
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ Mar 13 '15 at 13:52
  • $\begingroup$ What do you want to plot? $\endgroup$
    – m_goldberg
    Mar 13 '15 at 15:40
  • $\begingroup$ InputField is a bit tricky to use. May I suggest a manipulate? asq[b_] := b*b; Manipulate[ Grid[{{ListLinePlot[{a, asq[a]}], Framed[Style[asq[a], Red], Background -> LightRed]}}], {a, 1, 10, 1}, ControlType -> Slider] $\endgroup$ Mar 13 '15 at 15:51

I think you are working too hard. If you just want to put a plot below your input fields, you can do it like this.

asq[a_] := a*a

DynamicModule[{a = 2},
    Panel[Dynamic @
          {Style["Input number", Blue], InputField[Dynamic[a], Number]}, 
          {Style["Square of number", Red], 
           InputField[Dynamic[asq[a]], Enabled -> False, Background -> Red]}},
          Alignment -> Left],
        Plot[asq[x], {x, 0, a}]}],
      ImageMargins -> 10], 
    DefaultOptions -> 
      {InputField -> {ContinuousAction -> True, FieldSize -> {{5, 30}, {1, Infinity}}}}]]



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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