# What does DisplayFunction->Identity do to graphics functions?

Does DisplayFunction->Identity do anything at all in Mathematica 8?

In the third edition of Programming in Mathematica, Roman Maeder gives the following explanation:

The option setting DisplayFunction->Identity causes the graphics functions Plot[], Plot3D[], ParametricPlot[], and so on to generate the graphics in the normal way, but not to render the images. We use it if we want to manipulate the graphics further. Afterwards, we can render the images with Show[graphics,DisplayFunction->$DisplayFunction]. He is referring to the following piece of code: z = x + I y; cz = {Re[z], Im[z]}; vlines = Table[ N[cz], {x, -Pi/2, Pi/2, Pi/12} ]; vg = ParametricPlot[ Evaluate[vlines], {y, -1, 1}, DisplayFunction -> Identity ][]  SameQ tells me that even without DisplayFunction->Identity, I will still get the same result for vg. Is Maeder's precaution no longer necessary in Mathematica 8? • A use for DisplayFunction in later versions: (71345) Feb 16 '15 at 14:34 • Here is another application of DisplayFunction. Jul 25 '16 at 6:39 ## 4 Answers This option is not relevant since version 6 of Mathematica. Before version 6, graphics did not display immediately after evauating the (inert) Graphics[] expression. They could be shown using the Show command (it was a side-effect of Show). (This is the reason why the function which today is used to combine graphics has such an unusual name---Show.) So building graphics went like this: g = Graphics[ ... ] (* the output of this would be formatted simply as the string --Graphics-- *) Show[g] (* now the graphics was displayed *)  Show displayed the graphics by evaluating its display function. Plotting functions (such as Plot) called Show automatically. In version 6, any Graphics object is formatted by the front end as the image it represents (instead of the placeholder --Graphics--). Running the DisplayFunction is no longer needed (at least when using the standard notebook interface). But the mechanism is still in place, and we can try it out: g = Graphics[Circle[], DisplayFunction -> CreateDialog] (* this is shown the usual way---remember, the front end formats any Graphics expression as the "image"/drawing it represents *) Show[g] (* now CreateDialog is evaluated and a window with the graphics pops up *)  With the default version 8 DisplayFunction, which is Identity, Show would have returned the original graphics, as applying Identity to something just returns it as it is. I hope this explains the purpose of DisplayFunction. Edit: There are still a number of display mechanisms that use DisplayFunction. One is <<Version5Graphics mentioned by @Mr.Wizard. You can find some others by checking the files in $InstallationDirectory/SystemFiles/Kernel/Packages, and the readme file there. The available options depend on the operating system. On Windows, you can try for example, <<Terminal and <<JavaGraphics (try both when running the kernel in command line mode, and don't forget to use Show).

• That is a very interesting historical explanation! May 17 '12 at 16:30

==== EDIT: Applications/Usability - after @Jens comment ====

@Jens is right in his comment that this could be useful - thanks for bringing it up. You can define a function just once and then automate its application via global

SetOptions[Plot, DisplayFunction-> myFunctiom]


Now let see how it works.

===============================================================

In addition to the useful answers given, to figure out how things work, you can do a little experimenting of your own. First produce some usual plot

p=Plot[Sin[4 x]/x, {x, -9, 9}, Filling -> 0] And check its options which will reveal the default setting for DisplayFunction

Options[p]

{AspectRatio -> 1/GoldenRatio, Axes -> True,
AxesOrigin -> {0, 0}, DisplayFunction :> Identity,
PlotRange -> {{-9, 9}, {-0.868934, 0.863343}},
PlotRangeClipping -> True,


Now try experimenting:

Plot[Sin[x], {x, -6.6, 6.6}, DisplayFunction -> MyTestFunction] So you see it just wraps around. So you can now do things like

DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3},
ColorFunction -> "SunsetColors", Frame -> False,
DisplayFunction -> (GraphicsGrid[ImagePartition[#, 20]] &)] Which you of course could do just simply wrapping you custom function around your plot in the first place, unless you want to automate your actions as explained in the beginning of the post.

• This could be very useful for defining wrapper functions globally as in SetOptions[Plot, DisplayFunction-> myFunctiom].
– Jens
May 17 '12 at 16:45
• @Jens I was just wondering why anyone would use DisplayFunction instead of applying the function directly, and your comment showed up. May 17 '12 at 16:50
• @Jens Instead, one could simply change the value of $DisplayFunction, which is the actual default value of DisplayFunction. One thing ot pay attention to is that the display function won't get applied when evaluating a Graphics expression. It needs Show or some kind of plotting function. May 18 '12 at 7:43 • @Szabolcs Good point - I don't have any specific use in mind right now anyway... – Jens May 18 '12 at 14:02 Graphics rendering was fundamentally changed in Mathematica version 6. Before that graphics output was treated specially, like a Print statement. Now output graphics are treated much the same as any other expression, and output can be suppressed with ; (CompoundExpression). Between Versions 5 and 6 The graphics functionality has significantly changed. For compatibility purposes, use <<Version5Graphics to restore graphics capabilities from Mathematica 5. To restore the Mathematica 6 graphics capabilities, use <<Version6Graphics. Over 800 completely new built-in objects have been added, some of whose names may conflict with names already being used. The output form of a Graphics or Graphics3D object is now the rendered graphic rather than an output such as -Graphics-. $DisplayFunction is now set to Identity, so that no side effect happens by default when evaluating a graphic. To produce a side effect similar to Version 5 output, you can use the Print function to print the graphic.

So in fact DisplayFunction -> Identity is the default.

• Copying and pasting is faster than writing it up :P May 17 '12 at 16:16
• @Szabolcs I hardly get the chance to answer any questions these days. I'm trying! May 17 '12 at 16:18
• Something interesting: did you notice that there's <<Version7Graphics  as well? I didn't check the details, but I remember that when I looked at the code the front end executes upon connecting to the kernel, I had the impression that these files are (also?) used when it connects to an older version kernel. May 17 '12 at 16:23
• @Mr.Wizard The link to the list of changes will come in very useful as I read the book. Thank you. May 17 '12 at 16:27
• Mr.Wizard, and @MichaelWijaya: Not sure if this is what Mr.Wiz intended, but a quick list of changes (with links to more info) is here wolfram.com/mathematica/quick-revision-history.html
– rm -rf
May 17 '12 at 17:09

Actually, I know just one special case where DisplayFunction -> Identity is in fact still needed even with version 8:

As I mention in this answer, assume you have started JavaGraphics in a Kernel-only session to make plots. Now you decide you're done displaying plots and instead want to create only non-displayed plots for export. Then you have to do something like this session:

In:= <<JavaGraphics
-- Java graphics initialized --
(* Make interactive plots... *)
In:= p=Plot[x,{x,0,1}]
Out= -Graphics-
(* after some more plotting, I want to stop displaying and export only: *)
In:= r=Plot[x,{x,0,1},DisplayFunction->Identity];
In:= Export["r.pdf",r]
Out= r.pdf


The last plot isn't displayed but can be exported. Note that the semicolon ; does not determine whether a plot is displayed or not in this Kernel session. I.e., I could add the semicolon to line In` but it would make no difference.