Re: Plotting problems
- To: mathgroup at yoda.physics.unc.edu
- Subject: Re: Plotting problems
- From: twj
- Date: Wed, 18 Nov 92 11:19:01 CST
>I have written an Mma program whose last 3 lines are: > >ListPlot[nodePairs,PlotJoined->True,DisplayFunction->Identity] >Plot[S[x],{x,node[[1]],node[[n+1]]},DisplayFunction->Identity] >Show[%,%%,DisplayFunction :> $DisplayFunction] > >When the program is executed the Show function will sometimes(rarely) >properly overlay the two previous plots but more often, one of the >following error messages are displayed with no graph: > >Show::gtype: String is not a type of graphics. >Show::gtype: Show is not a type of graphics. > >However when the same 3 lines are executed in the notebook after the >program has bees run, the Show function produces the proper plot. > I understand this to mean that there is a block of code like so: foo[x_] := Block[{}, .... .... ListPlot[nodePairs,PlotJoined->True,DisplayFunction->Identity]; Plot[S[x],{x,node[[1]],node[[n+1]]},DisplayFunction->Identity]; Show[%,%%,DisplayFunction :> $DisplayFunction] ] your problem is that the % and %% refer to the history mechanism that records output as you use the mainloop of the Mathematica Kernel and go from one Input prompt to another. The % will refer to the result prior to the Input which started the execution of the above block and the %% to the result before that. If that is the problem it is quite natural that when you evaluate the lines independently you get the behaviour you expect. If this is your problem this will work. foo[x_] := Block[{p1, p2}, .... .... p1 = ListPlot[nodePairs,PlotJoined->True,DisplayFunction->Identity]; p2 = Plot[S[x],{x,node[[1]],node[[n+1]]},DisplayFunction->Identity]; Show[p1, p2, DisplayFunction :> $DisplayFunction] ] By the way this is absolutely a good way to generate pictures, use the built-in functions like ListPlot or Plot to do as much of the work as possible. Tom Wickham-Jones WRI