Re: Graphics and DisplayFunction
- To: mathgroup at smc.vnet.net
- Subject: [mg98181] Re: Graphics and DisplayFunction
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Wed, 1 Apr 2009 05:58:40 -0500 (EST)
- References: <gqsn9m$3tr$1@smc.vnet.net>
replicatorzed at gmail.com wrote:
> Does anyone know why the following code fails to return the second
> Graphics object?
>
> ListPlot[{1, 2, 3}, DisplayFunction -> Print];
> Graphics[{Circle[]}, DisplayFunction -> Print];
>
> Even the coloring of the syntax differs for the two: after ListPlot
> [...], the semicolon is red indicating its unnecessary presence, while
> the one after Graphics[...] is left black. I would think that with the
> generalized input of Mathematica 6, the two would behave the same way,
> but apparently they do not.
> I know how to solve this with Show. I just simply don't understand why
> these two behave differently, if both produce (without specifying
> DisplayFunction) Graphics objects:
>
>
> In[104]:= Print[InputForm[ListPlot[{1, 2, 3}]]];
> Print[InputForm[Graphics[{Circle[]}]]];
>
> During evaluation of In[104]:= Graphics[{Hue[0.67, 0.6, 0.6], Point
> [{{1., 1.}, {2., 2.}, {3., 3.}}]}, {AspectRatio -> GoldenRatio^(-1),
> Axes -> True, AxesOrigin -> {0, Automatic}, PlotRange -> Automatic,
> PlotRangeClipping -> True}]
>
> During evaluation of In[104]:= Graphics[{Circle[{0, 0}]}]
>
> In[106]:= Head[ListPlot[{1, 2, 3}]]
> Head[Graphics[{Circle[]}]]
>
> Out[106]= Graphics
>
> Out[107]= Graphics
>
As you said, both produce Graphics expressions. (More precisely,
Graphics *is* a Graphics expression.) But there's a difference: while
Graphics[] is just a way to *represent* graphics, plotting functions
also have a side effect of *displaying* the graphics expressions that
they produce.
In Mathematica <= 5.2 it worked like this: Graphics expressions were
formatted in the front end as --Graphics--, and they could be rendered
with Show[] (which called a function specified in DisplayFunction)
In Mathematica >= 6, Graphics expressions are formatted as the actual
picture they represent (in StandardForm/TranditionalForm). Apart from
this, everything works the same as in 5.2. Of course since the graphics
are formatted nicely in the front end, there's no need for displaying
them in an explicit way, so $DisplayFunction === Identity by default.
But suppose now that you can't/don't use the front end for some reason,
or use an alternative front end. Now it does make sense to use an
explicit command for showing the graphics. Try opening the command line
version, and type <<Terminal` or <<JavaGraphics`.
The reason for the semicolon not being highlighted after Graphics[]; is
that in 5.2 no one typed Graphics[...] expecting to get a plot, but
using Plot[...]; was quite common (to suppress displaying the return
value, --Graphics--)