Re: rescalling(sp)

*To*: mathgroup <mathgroup at yoda.physics.unc.edu>*Subject*: Re: rescalling(sp)*From*: HAY at leicester.ac.uk*Date*: Sat, 7 NOV 92 21:27:52 GMT

Jack Lee writes in reply to Sherman C. Reed (reed at ee.uta.edu) > I've written a function called ShowScaled, which behaves essentially the > same as Show, except that it accepts an additional argument, Scale -> n, > which specifies that the plot is to be scaled so that the entire plot area > is n units by n units (i.e. one unit on either axis corresponds to exactly > 1/n of the total width of the graph). The default is Scale -> 10. The following code extends his idea and meets at least one of his needs -- independent scaling of x- and y- coordinates. Unlike Jack's it does not make use of Epilog -- perhaps someone could check on whether anything is lost by this change. I have tried to make the behaviour as close as posible to that of Show. So that , for example Prolog and Epilog and Label are passed on (in Jacks version FullGraphics did not do this). The user's options can override those in the given graphics object. More controlcould be given over the original graphics but too keep things simple I have adopted the aim of taking this as it is and just scaling and positioning it. ============================================================================ ShowScaled2::usage = "ShowScaled[graphics, options, xScale -> xn, yScale ->yn] displays a 2-dimensional graphics object, scaled so that one x-unit occupies exactly 1/xn of the total width of the graph and one y-unit occupies exactly 1/yn of the total width of the graph (Defaults for xn, yn are 10) It accepts the same options as Show."; ShowScaled2[args__, opts___Rule] := Module[{plot,center,scales}, (* find the scale to be used, Default = 10*) scales = {xScale, yScale}/. {opts, xScale->10, yScale->10}; (* Create a graphics object using all the user's Graphics options *); plot = Show[ args , DisplayFunction -> Identity]; (* Pull out the PlotRange that was actually plotted*) pltrnge = FullOptions[plot,PlotRange][[{1,2}]]; (*Find the center of plot *) center = Plus@@Transpose[pltrnge]/2 ; (* AA: Turn the graphics object into a list of graphics primitives to retain the axes and ticks etc at the final display Prolog, Epilog, PlotLabel are lost here *) gr = FullGraphics[ plot]/.{l__, Text[]} -> {l}; (* Finally, display the scaled plot. *) Show[ gr, PlotRange -> center + Outer[Times, scales,{-1, 1}/2], Sequence@@DeleteCases[{opts}, (xScale|yScale)->_ ], AspectRatio -> Automatic, Axes -> False, DisplayFunction -> $DisplayFunction, (* restore any Prolog, Epilog, PlotLabel options lost by FullGraphics at AA above *) Sequence@@ Cases[ Options[plot], Literal[PlotLabel|Prolog|Epilog ->_] (* these changed, and might be set by an option *) ] ] ]; Allan Hayes hay at leicester.ac.uk