# Difference between Prolog and explicit Graphics

Is there any difference between

Plot[x^2, {x, -1.5, 1.5}, Prolog -> {Pink, Disk[{0, 1}, 1]}, PlotStyle -> Thick,
AspectRatio -> Automatic]


and

Show[Graphics[{Pink, Disk[{0, 1}, 1]}], Plot[x^2, {x, -1.5, 1.5}],
PlotStyle -> Thick, AspectRatio -> Automatic, Axes -> True]


The output appears to be identical, and the description of Prolog doesn't seem to describe anything different. (I have the same question about Epilog).

• No, there isn't any difference. Show takes its options from the first argument so you need to specify explicitly all the options of Plot to get it right, but you seem to be aware of that. Options[Plot] can help. Epilog is simpler in that Graphics naturally comes after Plot. If you want to make sure you can use FullForm to compare the end result of the two pieces of code. Mar 4 '17 at 19:02
• Thanks. Could you turn that into an answer so I can accept and we won't have unanswered questions lying about? (I always forget about using FullForm for these kinds of things). Mar 4 '17 at 19:58
• I was waiting for more careful analysis such as that by m_goldberg and Mr.Wizard. Even though, in the main, the simple analysis provided by my comment is correct (for display purposes), I did not look for all the subtleties. Mar 4 '17 at 21:44

The difference is in the structure of the expression rather than the way it is displayed.

Let us name the expressions g1 and g2 for reference:

g1 = Plot[x^2, {x, -1.5, 1.5}, Prolog -> {Pink, Disk[{0, 1}, 1]},
PlotStyle -> Thick, AspectRatio -> Automatic];

g2 = Show[Graphics[{Pink, Disk[{0, 1}, 1]}], Plot[x^2, {x, -1.5, 1.5}],
PlotStyle -> Thick, AspectRatio -> Automatic, Axes -> True];


Observe that in g1 the Prolog remains an option:

Options[g1, Prolog]

{Prolog -> {RGBColor[1, 0.5, 0.5], Disk[{0, 1}, 1]}}


This means it is not straightforward to combine this with another Prolog:

Show[g1, Prolog -> {LightBlue, Polygon[{{1, 0}, {0, Sqrt}, {-1, 0}}]}] g2 however can directly receive a Prolog without conflict:

Show[g2, Prolog -> {LightBlue, Polygon[{{1, 0}, {0, Sqrt}, {-1, 0}}]}] The same mechanism applies to Epilog as well.

## What's the purpose of Prolog and Epilog?

You remarked:

So based on [these answers] why would you want to ever use Prolog or Epilog?

Convenience, mainly. They let one quickly and easily combine up to three layers of graphics in a single Plot expression. For more complicated constructions a List in Graphics often works better.

However there are cases where I know of no other way to get the desired output, one being:

Here is another issue. PlotRange -> All does not consider the contents of Prolog or Epilog when calculating the viewport for the rendered graphics.

The code

Show[
Graphics[{Pink, Disk[{0, 1}, 1.5]}],
Plot[x^2, {x, -1.75, 1.75},
PlotStyle -> Thick,
AspectRatio -> Automatic],
Axes -> True,
PlotRange -> All


renders everything. while the code

Plot[x^2, {x, -1.75, 1.75},
Prolog -> {Pink, Disk[{0, 1}, 1.5]},
PlotRange -> All,
PlotStyle -> Thick,
AspectRatio -> Automatic]


doesn't render the pink disk completely because it was specified in a prolog. • So based on your answer (and @MrWizard's), why would you want to ever use Prolog or Epilog? Mar 4 '17 at 21:43