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 would like to combine a dynamic module with a manipulation, whilst maintaining the functionality of both. I have tried things like Show and Epilog -> Inset@..., but neither seem to work. The code for both dynamic module & manipulation are as follows:

Manipulate[
Plot[x^n, {x, 0, 5}, PlotRange -> {{0, 5}, {0, 5}}, GridLines -> {Range@5, Range@5}, 
GridLinesStyle -> Directive[GrayLevel[0.8], Dashed], AspectRatio -> Automatic, 
PlotStyle -> Thick, Axes -> False, ImageSize -> 200], {n, -3, 3},

DynamicModule[{x = 11}, Grid[Map[Button[ToString@#, x = #, Background -> 
Dynamic[If[Divisible[#, x], Green, Red]], ImageSize -> {40, 40}, Appearance -> 
"Frameless"] &, RandomInteger[{1, 10}, {5, 5}], {2}], Frame -> All, 
FrameStyle -> Dashed, Spacings -> {.2, .2}]]]

produces:

enter image description here

Functionality in the above illustration is preserved, but I would really like one to overlay the other (plot on top 'layer'). I have included the grid on both to show how I would like to align them.

I have looked here, and here, to no avail :(

This is a slimmed-down version of a previous (deleted) post - I hope it is a little clearer :)

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Perhaps this?

Manipulate[
 Plot[x^n, {x, 0, 5}, PlotRange -> {{0, 5}, {0, 5}}, 
  GridLines -> {Range@5, Range@5}, 
  GridLinesStyle -> Directive[GrayLevel[0.8], Dashed], 
  AspectRatio -> Automatic, PlotStyle -> Thick, Axes -> False, 
  ImageSize -> 200, 
  Prolog -> 
   Inset@DynamicModule[{x = 11}, 
     Grid[
       Map[Button[ToString@#, x = #, 
          Background -> Dynamic[If[Mod[#, x] == 0, Green, Red]], 
          ImageSize -> {40, 40}, Appearance -> "Frameless"] &, 
        RandomInteger[{1, 10}, {5, 5}], {2}], Frame -> All, 
       FrameStyle -> Dashed, Spacings -> {.2, .2}]]],
 {n, -3, 3}]

Manipulate output

share|improve this answer
    
+1 very nice. Prolog! :) –  belisarius Nov 22 '13 at 2:13
    
@ Michael E2, Thank you very much for your help on this - if this was what I was trying to achieve, I would be very happy with your solution, but I am trying to stitch together two longer, more complicated pieces of code (see update). I posted this as the question originally, but was advised to make it shorter ... I am really struggling with this though - pulling my hair out! :/ –  martin Nov 22 '13 at 2:14
1  
@martin You should be aware that the purpose of this site isn't helping you with your application, but with the Mathematica platform. Posting your full code will attract downvotes, cause people to skip reading your questions, you will probably catch dandruff and your fridge will stop working. Seriously, don't do that –  belisarius Nov 22 '13 at 2:19
    
@ belisarius, Point taken - the struggle continues! –  martin Nov 22 '13 at 2:21
1  
@martin You might consider using ClickPane[graphics, func] instead of Button. You can use func to set your variable x and change the color of Rectangles (like you do the background) in response to mouse clicks. It's easier to combine graphics than mix graphics and non-graphics. –  Michael E2 Nov 22 '13 at 3:36

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.