0
$\begingroup$

I would like to superpose several plots : - one which uses a Manipulate function with a parameter - and 4 plots which stays at the background and which are instanciations with four fix values of the parameter which is used in the Manipulate function.

Here you can find the function that i'm plotting :

AbsDepdimen[λ_][r_]:=1/Sqrt[(1 - r^2)^2 + 4 r^2 λ^2]

Here the code that i have tried without success :

Show[Manipulate[
  Plot[AbsDepdimen[\[Lambda]][r], {r, 0, 2}, PlotRange -> {0, 5}, 
   AxesLabel -> {Subscript[\[Omega], r], \!\(TraditionalForm\`
\*FractionBox[\(X\), 
SubscriptBox[\(X\), \(st\)]]\)}], {\[Lambda], 0, 2}], 
 Plot[AbsDepdimen[0.0001][r], {r, 0, 2}, PlotRange -> {0, 5}, 
  AxesLabel -> {Subscript[\[Omega], r], \!\(TraditionalForm\`
\*FractionBox[\(X\), 
SubscriptBox[\(X\), \(st\)]]\)}],
 Plot[AbsDepdimen[0.02][r], {r, 0, 2}, PlotRange -> {0, 5}, 
  AxesLabel -> {Subscript[\[Omega], r], \!\(TraditionalForm\`
\*FractionBox[\(X\), 
SubscriptBox[\(X\), \(st\)]]\)}],
 Plot[AbsDepdimen[0.2][r], {r, 0, 2}, PlotRange -> {0, 5}, 
  AxesLabel -> {Subscript[\[Omega], r], \!\(TraditionalForm\`
\*FractionBox[\(X\), 
SubscriptBox[\(X\), \(st\)]]\)}],
 Plot[AbsDepdimen[0.8][r], {r, 0, 2}, PlotRange -> {0, 5}, 
  AxesLabel -> {Subscript[\[Omega], r], \!\(TraditionalForm\`
\*FractionBox[\(X\), 
SubscriptBox[\(X\), \(st\)]]\)}]]

Can you help me to find a way to combine Manipulate[Plot[]] and Plot[] (the classic one) in on the same graph as it is possible to do with Show function ?

Thank you for your help

$\endgroup$
1
$\begingroup$

Kuba nailed it in his comment, but to unpack explicitly:

Slow version with Show

Manipulate[Show[
    Plot[AbsDepdimen[\[Lambda]][r], {r, 0, 2}, PlotRange -> {0, 5}, 
      AxesLabel -> {Subscript[\[Omega], r], X/Subscript[X, st]}],
   Plot[AbsDepdimen[0.0001][r], {r, 0, 2}, PlotRange -> {0, 5}, 
     AxesLabel -> {Subscript[\[Omega], r], X/Subscript[X, st]}],
   Plot[AbsDepdimen[0.02][r], {r, 0, 2}, PlotRange -> {0, 5}, 
     AxesLabel -> {Subscript[\[Omega], r], X/Subscript[X, st]}],
   Plot[AbsDepdimen[0.2][r], {r, 0, 2}, PlotRange -> {0, 5}, 
     AxesLabel -> {Subscript[\[Omega], r], {Subscript[\[Omega], r], X/Subscript[X, st]}],
   Plot[AbsDepdimen[0.8][r], {r, 0, 2}, PlotRange -> {0, 5}, 
     AxesLabel -> {Subscript[\[Omega], r], X/Subscript[X, st]}]], {\[Lambda], 0, 2}]

Faster version with Graphics and Dynamic:

The only glitch here is you will possibly track Plot arguments you haven't cared about before like AspectRatio etc, supplied at the end of your Graphics statement.

Manipulate[Graphics[{
     Dynamic@First@Plot[AbsDepdimen[\[Lambda]][r], {r, 0, 2}],
    Dynamic@First@Plot[AbsDepdimen[0.0001][r], {r, 0, 2}],
    Dynamic@First@Plot[AbsDepdimen[0.02][r], {r, 0, 2}],
    Dynamic@First@Plot[AbsDepdimen[0.2][r], {r, 0, 2}],
    Dynamic@First@Plot[AbsDepdimen[0.8][r], {r, 0, 2}]}, 
  Frame -> True, 
  FrameLabel ->  {Subscript[\[Omega], r], X/Subscript[X, st]}, PlotRange -> {0, 5}, 
  AspectRatio -> 1/GoldenRatio], {\[Lambda], 0, 2}]

( I chose to use a Frame, but if you really prefer Axes the options are:

Axes -> True, AxesLabel ->  {Subscript[\[Omega], r], X/Subscript[X, st]}

)


Update Clarification due to Nasser's reasonable question.

As Nasser points out, it's not necessary to tag all the static guys with Dynamic (although I don't notice a penalty). In contrast I definitely run into a lag response if I don't tag the guys who are (potentially independently) changing under the manipulate. I suspect this is a result of Mathematica's effort to only update nested dynamic things when they update as documented here. Fair credit: I only bothered reading any of this because of Kuba's fantastic discussion.

To be explicit if only the first guy changes (as it does in the OP's example), but we don't want MMA to re-render everything else, seems we can get away with only nesting its dynamic:

Manipulate[Graphics[{
     Dynamic@First@Plot[AbsDepdimen[\[Lambda]][r], {r, 0, 2}],
    First@Plot[AbsDepdimen[0.0001][r], {r, 0, 2}],
    First@Plot[AbsDepdimen[0.02][r], {r, 0, 2}],
    First@Plot[AbsDepdimen[0.2][r], {r, 0, 2}],
    First@Plot[AbsDepdimen[0.8][r], {r, 0, 2}]}, 
  Frame -> True, 
  FrameLabel ->  {Subscript[\[Omega], r], X/Subscript[X, st]}, PlotRange -> {0, 5}, 
  AspectRatio -> 1/GoldenRatio], {\[Lambda], 0, 2}]
$\endgroup$
  • 3
    $\begingroup$ Why do you need to add Dynamic to Dynamic@First@Plot etc...? Why not just First@Plot? $\endgroup$ – Nasser Sep 4 '17 at 20:55
  • $\begingroup$ Strictly speaking I guess to get the speed boost you only need the Dynamic on the thing that's getting manipulated. Now I'm under the habit of applying generically when building something like this since usually not so many of the plots are static. But why Dynamic is helpful on the first guy, look at the very answer Kuba linked to: here. I'll update my answer to reflect. $\endgroup$ – John Joseph M. Carrasco Sep 4 '17 at 21:02

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.