Re: Suppressing display of LogPlots
- To: mathgroup at smc.vnet.net
- Subject: [mg22614] Re: Suppressing display of LogPlots
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Tue, 14 Mar 2000 22:46:27 -0500 (EST)
- References: <8aejj2$3aj@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Dr Dan, The likely cause is very interesting for any option that are set with RuleDelayed( :> ). Please make a copy of the file Graphics.m in the same folder as the original and call it myGraphics.m. Looking at this we see In the usage notes, DisplayFunction is set with RuleDelayed : DisplayFunction :> <value> not Rule: DisplayFunction -> <value> However we get << Graphics`Graphics` Block[{$DisplayFunction = Identity}, LogLinearPlot[Sin[x], {x, 0, 3*Pi}]]; Options[%, DisplayFunction] {DisplayFunction -> Identity, DisplayFunction :> Identity} Now, using Find to find DisplayFunction -> we find several inocuous cases but eventually reach a case inside (1) Show[g, DisplayFunction -> disp, PlotRange -> r, AxesOrigin -> ao ] We find that dis was defined earlier by (2) {scale, disp, ao} = {ScaleFunction, DisplayFunction, AxesOrigin}/. Flatten[{opts}]/.Options[ScaledPlot]; Although this is a common way of extracting the values for options it is cause of the problem, because it allows $DisplayFunction in DisplayFunction :> $DisplayFunction to be evaluated inside Block[ ..] using the temporary setting $DisplayFunction = Identity. One way out is to replace (2) with {scale, ao} = {ScaleFunction, AxesOrigin}/. Flatten[{opts}]/.Options[ScaledPlot]; dis = Cases[Flatten[{opts,Options[ScaledPlot]}], _[DisplayFunction,_]][[1]]; This gives dis = DisplayFunction:>$DisplayFunction with $DisplayFunction unevaluated, because RuleDelayed has the attribute HoldRest. and replace (1) with Show[g, disp, PlotRange -> r, AxesOrigin -> ao ]. There are two subsequent examples of this kind of problem in the code that can be handled in the same way. After dealing with these we get. << Graphics`myGraphics` Block[{$DisplayFunction = Identity}, LogLinearPlot[Sin[x], {x, 0, 3*Pi}]]; Options[%, DisplayFunction] {DisplayFunction :> $DisplayFunction, DisplayFunction :> Identity} Show[%%]; (*displays the picture*) You might like to tidy up so that DisplayFunction :> Identity is not left in. Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "Dr Dan" <drdanw at my-deja.com> wrote in message news:8aejj2$3aj at smc.vnet.net... > There is a programming oversight (er, bug) in the Graphics` package > that interferes with the delayed evaluation of DisplayFunction > options. A common trick to suppress the display of graphics is to wrap > Plot in a Block function: > > In[1]:= > Block[{$DisplayFunction = Identity}, > g1 = Plot[Sin[x], {x, 0, 3*Pi}]; ]; > > In[2]:= > Show[g1] > > ---------plot deleted > Out[2]= > -Graphics- > > However, this trick does not work for many plot types defined in the > Graphics`Graphics` package: > > In[3]:= > << "Graphics`Graphics`" > > In[4]:= > Block[{$DisplayFunction = Identity}, > g2 = LogLinearPlot[Sin[x], {x, 0, 3*Pi}]; ]; > > In[5]:= > Show[g2] > > ------------- plot doesn't show! > Out[5]= > -Graphics- > > We can see why the plot does not display outside the Block by checking > the DisplayFunction options in the graphic: > > In[6]:= > Options[g2, DisplayFunction] > > Out[6]= > {DisplayFunction -> Identity, DisplayFunction :> Identity} > > I have tracked this bug to the utility functions ScaledPlot and > ScaledListPlot in Graphics.m. Since I am not brave enough to attempt > to fix the code, I created the following hack: > > DisplayFunctionHack[Graphics[args__, > (opts___)?OptionQ]] := Graphics[args, > {Flatten[{DisplayFunction :> $DisplayFunction, > DeleteCases[Flatten[{opts}], (Rule | RuleDelayed)[ > DisplayFunction, _]]}]}] > > The DeleteCases is not strictly necessary, but I like to clean up. We > can see the effect of the hack by checking the options of the graphic > again: > > In[8]:= > g3 = DisplayFunctionHack[g2]; > > In[9]:= > Options[g3, DisplayFunction] > > Out[9]= > {DisplayFunction :> $DisplayFunction} > > Now the graphics displays properly: > > In[10]:= > Show[g3] > > ----------------graphic deleted, but trust me, it was here. > Out[10]= > -Graphics- > > > > Sent via Deja.com http://www.deja.com/ > Before you buy. >
- Follow-Ups:
- Re: Re: Suppressing display of LogPlots
- From: Hartmut Wolf <hwolf@debis.com>
- Re: Re: Suppressing display of LogPlots