Prev: Finding how to do things by trial and error
Next: SetOptions[Plot, .Z..] vs using Plot[, .Z..] behaves differently when Z is Dynamics
From: Nasser M. Abbasi on 5 Dec 2009 06:35 Ver 7. Hello; Without the use of DynamicModule[], just some simple code. I have one Plot and one ListPlot, and I wanted to combine them. Ofcourse I can use Show[], but when one of the above objects is Dynamics, I can't do that. I tried many things, and so far, no success. This is what I have and what I tried: ------------------- v = VerticalSlider[Dynamic[maxy], {0.1, 4}, Appearance -> "LeftArrow"]; p0 = ListPlot[Range[10]]; p1 = Dynamic[Plot[Cos[x], {x, -Pi, Pi}, PlotRange -> {{-Pi, Pi}, {-maxy, maxy}}]]; Row[{ver, p1, p0}] ------------------- The above works, but p1 and p0 are not combined. But I wanted to combine p1 and p0 into ONE graphics, except now this will not work as p1 is dynamics. I tried Row[{ver, Show[p1, p0]}] Row[{ver, Dynamic(a)Show[p1, p0]}] I really thought Dynamic[Show[....]] will do it? tried few other things....I need to read more about Dynamics, but meanwhile in case I do not see it, any idea how this can be done? Notice that p0 is a ListPlot and not a Plot. Else I would have been able to simply use one Dynamic(a)Plot[...] to combine the plots and not even need Show[], like this (assuming the second plot is Cos[x]) v = VerticalSlider[Dynamic[maxy], {0.1, 4}, Appearance -> "LeftArrow"]; p1 = Dynamic[Plot[{Cos[x], Sin[x]}, {x, -Pi, Pi}, PlotRange -> {{-Pi, Pi}, {-maxy, maxy}}]]; Row[{ver, p1}] and this would have worked. So, how to combine Dynamic graphics objects? thanks --Nasser
From: Bob Hanlon on 6 Dec 2009 01:31 Manipulate[ Show[ ListPlot[Range[10]], Plot[Cos[x], {x, -Pi, Pi}], PlotRange -> {{-Pi, Pi}, {-maxy, maxy}}], {{maxy, 1.1}, 0.1, 4, ControlType -> VerticalSlider, ControlPlacement -> Left, Appearance -> {"LeftArrow"}}, Paneled -> False] Bob Hanlon ---- "Nasser M. Abbasi" <nma(a)12000.org> wrote: ============= Ver 7. Hello; Without the use of DynamicModule[], just some simple code. I have one Plot and one ListPlot, and I wanted to combine them. Ofcourse I can use Show[], but when one of the above objects is Dynamics, I can't do that. I tried many things, and so far, no success. This is what I have and what I tried: ------------------- v = VerticalSlider[Dynamic[maxy], {0.1, 4}, Appearance -> "LeftArrow"]; p0 = ListPlot[Range[10]]; p1 = Dynamic[Plot[Cos[x], {x, -Pi, Pi}, PlotRange -> {{-Pi, Pi}, {-maxy, maxy}}]]; Row[{ver, p1, p0}] ------------------- The above works, but p1 and p0 are not combined. But I wanted to combine p1 and p0 into ONE graphics, except now this will not work as p1 is dynamics. I tried Row[{ver, Show[p1, p0]}] Row[{ver, Dynamic(a)Show[p1, p0]}] I really thought Dynamic[Show[....]] will do it? tried few other things....I need to read more about Dynamics, but meanwhile in case I do not see it, any idea how this can be done? Notice that p0 is a ListPlot and not a Plot. Else I would have been able to simply use one Dynamic(a)Plot[...] to combine the plots and not even need Show[], like this (assuming the second plot is Cos[x]) v = VerticalSlider[Dynamic[maxy], {0.1, 4}, Appearance -> "LeftArrow"]; p1 = Dynamic[Plot[{Cos[x], Sin[x]}, {x, -Pi, Pi}, PlotRange -> {{-Pi, Pi}, {-maxy, maxy}}]]; Row[{ver, p1}] and this would have worked. So, how to combine Dynamic graphics objects? thanks --Nasser
From: Nasser M. Abbasi on 6 Dec 2009 01:31 From: "John Fultz" <jfultz(a)wolfram.com> "Show doesn't know how to deal with something that has the head Dynamic." Thanks for the info. But the above raises the question as to why then was the above not told to the user as part of the error message given? The error message simply said that it could not combine the graphics. Never said why. "Show::gcomb: "Could not combine the graphics objects in" but WHY?? That is the biggest problem I have with the Mathematica error messages. If the error message where a little helpful, then one would not have to scratch their head all the time wondering where is the problem and why. Don't you agree? I went over help for Show again and again, and I do not see anywhere it said that. And the examples I saw for Plot which uses a Dynamic was to wrap a Plot with Dynamics, do I did that, i.e. to write p=Dynamics(a)Plot[....]. "if you're going to spend time reading documentation, please make sure to read (again, if you've already read it before, because it's *very* relevant here) my post from February of this year... http://forums.wolfram.com/mathgroup/archive/2009/Feb/msg00424.html " I've just printed it out and will read it carefully. "...which I've referenced several times on this list. So the solution is to wrap the Dynamic around Show *and* to remove the Dynamic from inside of Show." Good to know, I'll add this to my Mathematica cheat sheat. But again, this I think should be documented in the help for show, may be under possible issues, and also the error messages can be improved allot to help users find where the problem is. If I want something from version 8, it would be a more detailed and useful error messages. This will go a long way to make programming in Mathematica a more pleasant endover. " v = VerticalSlider[Dynamic[maxy], {0.1, 4}, Appearance -> "LeftArrow"]; p0 = ListPlot[Range[10]]; p1 := Plot[Cos[x], {x, -Pi, Pi}, PlotRange -> {{-Pi, Pi}, {-maxy, maxy}}]; Row[{ver, Dynamic[Show[{p1, p0}]]}] And note again (repeating the theme from the last email I just sent you) how I had to use SetDelayed for p1 here to make sure that things work as expected regardless of the present global state." Thanks again John, --Nasser On Sat, 5 Dec 2009 06:35:13 -0500 (EST), Nasser M. Abbasi wrote: > Ver 7. > > Hello; > > Without the use of DynamicModule[], just some simple code. > > I have one Plot and one ListPlot, and I wanted to combine them. Ofcourse I > can use Show[], but when one of the above objects is Dynamics, I can't do > that. I tried many things, and so far, no success. > > This is what I have and what I tried: > > ------------------- > v = VerticalSlider[Dynamic[maxy], {0.1, 4}, Appearance -> "LeftArrow"]; > p0 = ListPlot[Range[10]]; > p1 = Dynamic[Plot[Cos[x], {x, -Pi, Pi}, PlotRange -> {{-Pi, Pi}, {-maxy, > maxy}}]]; > > Row[{ver, p1, p0}] > ------------------- > > The above works, but p1 and p0 are not combined. > > But I wanted to combine p1 and p0 into ONE graphics, except now this will > not work as p1 is dynamics. I tried > > Row[{ver, Show[p1, p0]}] > Row[{ver, Dynamic(a)Show[p1, p0]}] > > I really thought Dynamic[Show[....]] will do it? > > tried few other things....I need to read more about Dynamics, but > meanwhile > in case I do not see it, any idea how this can be done? > > Notice that p0 is a ListPlot and not a Plot. Else I would have been able > to > simply use one Dynamic(a)Plot[...] to combine the plots and not even need > Show[], like this (assuming the second plot is Cos[x]) > > v = VerticalSlider[Dynamic[maxy], {0.1, 4}, Appearance -> "LeftArrow"]; > p1 = Dynamic[Plot[{Cos[x], Sin[x]}, {x, -Pi, Pi}, PlotRange -> {{-Pi, Pi}, > {-maxy, maxy}}]]; > Row[{ver, p1}] > > and this would have worked. > > So, how to combine Dynamic graphics objects? > > thanks > --Nasser
From: David Park on 6 Dec 2009 01:33 Nasser, This is easy with Presentations and custom dynamics. I did change the ListPlot to something that would be more overlapping with the Cos plot. I calculate the contents of the two plots outside of the DynamicModule just to show they are not being dynamically updated. Only the PlotRange is dynamically updated. Needs["Presentations`Master`"] listdraw = ListDraw[Table[{x, x}, {x, -3, 3, .5}]]; cosdraw = Draw[Cos[x], {x, -\[Pi], \[Pi]}]; DynamicModule[ {maxy = 1}, Panel[ Row[ {VerticalSlider[Dynamic[maxy], {0.1, 4}, Appearance -> "LeftArrow"], Draw2D[ {AbsolutePointSize[4], listdraw, cosdraw}, AspectRatio -> 1, Frame -> True, PlotRange -> Dynamic@{{-\[Pi], \[Pi]}, {-maxy, maxy}}, ImageSize -> {300, 300}, ImagePadding -> {{30, 10}, {30, 10}}](* Draw2D *) }](* Row *), Style["Nasser's Custom Dynamic II", 16](* Panel *), ImageSize -> {380, 330}] ] David Park djmpark(a)comcast.net http://home.comcast.net/~djmpark/ From: Nasser M. Abbasi [mailto:nma(a)12000.org] Ver 7. Hello; Without the use of DynamicModule[], just some simple code. I have one Plot and one ListPlot, and I wanted to combine them. Ofcourse I can use Show[], but when one of the above objects is Dynamics, I can't do that. I tried many things, and so far, no success. This is what I have and what I tried: ------------------- v = VerticalSlider[Dynamic[maxy], {0.1, 4}, Appearance -> "LeftArrow"]; p0 = ListPlot[Range[10]]; p1 = Dynamic[Plot[Cos[x], {x, -Pi, Pi}, PlotRange -> {{-Pi, Pi}, {-maxy, maxy}}]]; Row[{ver, p1, p0}] ------------------- The above works, but p1 and p0 are not combined. But I wanted to combine p1 and p0 into ONE graphics, except now this will not work as p1 is dynamics. I tried Row[{ver, Show[p1, p0]}] Row[{ver, Dynamic(a)Show[p1, p0]}] I really thought Dynamic[Show[....]] will do it? tried few other things....I need to read more about Dynamics, but meanwhile in case I do not see it, any idea how this can be done? Notice that p0 is a ListPlot and not a Plot. Else I would have been able to simply use one Dynamic(a)Plot[...] to combine the plots and not even need Show[], like this (assuming the second plot is Cos[x]) v = VerticalSlider[Dynamic[maxy], {0.1, 4}, Appearance -> "LeftArrow"]; p1 = Dynamic[Plot[{Cos[x], Sin[x]}, {x, -Pi, Pi}, PlotRange -> {{-Pi, Pi}, {-maxy, maxy}}]]; Row[{ver, p1}] and this would have worked. So, how to combine Dynamic graphics objects? thanks --Nasser
From: John Fultz on 6 Dec 2009 01:37
Show doesn't know how to deal with something that has the head Dynamic. If you're going to spend time reading documentation, please make sure to read (again, if you've already read it before, because it's *very* relevant here) my post from February of this year... http://forums.wolfram.com/mathgroup/archive/2009/Feb/msg00424.html ....which I've referenced several times on this list. So the solution is to wrap the Dynamic around Show *and* to remove the Dynamic from inside of Show. v = VerticalSlider[Dynamic[maxy], {0.1, 4}, Appearance -> "LeftArrow"]; p0 = ListPlot[Range[10]]; p1 := Plot[Cos[x], {x, -Pi, Pi}, PlotRange -> {{-Pi, Pi}, {-maxy, maxy}}]; Row[{ver, Dynamic[Show[{p1, p0}]]}] And note again (repeating the theme from the last email I just sent you) how I had to use SetDelayed for p1 here to make sure that things work as expected regardless of the present global state. Sincerely, John Fultz jfultz(a)wolfram.com User Interface Group Wolfram Research, Inc. On Sat, 5 Dec 2009 06:35:13 -0500 (EST), Nasser M. Abbasi wrote: > Ver 7. > > Hello; > > Without the use of DynamicModule[], just some simple code. > > I have one Plot and one ListPlot, and I wanted to combine them. Ofcourse I > can use Show[], but when one of the above objects is Dynamics, I can't do > that. I tried many things, and so far, no success. > > This is what I have and what I tried: > > ------------------- > v = VerticalSlider[Dynamic[maxy], {0.1, 4}, Appearance -> "LeftArrow"]; > p0 = ListPlot[Range[10]]; > p1 = Dynamic[Plot[Cos[x], {x, -Pi, Pi}, PlotRange -> {{-Pi, Pi}, {-maxy, > maxy}}]]; > > Row[{ver, p1, p0}] > ------------------- > > The above works, but p1 and p0 are not combined. > > But I wanted to combine p1 and p0 into ONE graphics, except now this will > not work as p1 is dynamics. I tried > > Row[{ver, Show[p1, p0]}] > Row[{ver, Dynamic(a)Show[p1, p0]}] > > I really thought Dynamic[Show[....]] will do it? > > tried few other things....I need to read more about Dynamics, but > meanwhile > in case I do not see it, any idea how this can be done? > > Notice that p0 is a ListPlot and not a Plot. Else I would have been able > to > simply use one Dynamic(a)Plot[...] to combine the plots and not even need > Show[], like this (assuming the second plot is Cos[x]) > > v = VerticalSlider[Dynamic[maxy], {0.1, 4}, Appearance -> "LeftArrow"]; > p1 = Dynamic[Plot[{Cos[x], Sin[x]}, {x, -Pi, Pi}, PlotRange -> {{-Pi,= Pi}, > {-maxy, maxy}}]]; > Row[{ver, p1}] > > and this would have worked. > > So, how to combine Dynamic graphics objects? > > thanks > --Nasser |