# Why does the order of arguments in Show influence the result? [duplicate]

I am wondering why there is a difference in the results from evaluating the two expressions, which differ only in the order of the arguments given to Show.

When I run

Animate[Show[spring[t], bob[t], traj], {t, 0, 20}]


the animation is different from

Animate[Show[traj, spring[t], bob[t]], {t, 0, 20}]


Parts of the plot get cut off, depending on the order of the arguments.

## marked as duplicate by J. M. is computer-less♦Dec 28 '16 at 5:24

• Probably because Show takes options from the first argument which is different for those cases. – Kuba Mar 22 '14 at 22:16
• Thank you for posting the full code. I removed it to make the question easier to follow and more useful for future visitors, as this is a general problem and not related to the specific details of the code. (I haven't been able to find a good duplicate though one might exist.) – Szabolcs Mar 22 '14 at 23:22
• From Show, "Details": "Show[g1, g2,...] or Show[{g1, g2,...}] concatenates the graphics primitives in the gi, effectively overlaying the graphics." And: "The lists of non-default options in the gi are concatenated." – Michael E2 Mar 22 '14 at 23:39
• @Michael Your second citation looks like a mistake in the documentation: actually Show does not care about options in gi other than g1 (AFAIK). – Alexey Popkov Mar 23 '14 at 1:33
• @AlexeyPopkov I suppose it depends on what is meant. Consider p3 = Show[ p1 = Plot[x^2, {x, 0, 2}], p2 = Plot[2 Sin[x], {x, 0, 3}, ImageMargins -> 100] ]; AbsoluteOptions[p1] The first occurrence of an option overrides later ones, which are deleted. ImageMargins is set to 0. in p1, which would cause ImageMargins -> 100 to be ignored, IF that is how it works. In effect, then, what you say is true, too, since the first plot seems to set every possible option, or at least the documented ones. In any case, the doc. is at least misleading. – Michael E2 Mar 23 '14 at 1:55

The order of arguments in Show makes a difference in two ways:

1. The Graphics expression produced by Show will inherit options from the first argument

2. The first argument will appear in the bottom layer, the last one in the top layer.

The most common problem (1) causes is that the plot range is inherited from the first argument, causing parts of the second one to be cut off. For example:

plot1 = Plot[x^2/20, {x, 0, 5}]
plot2 = Plot[Sin[x], {x, 0, 5}]

Show[plot1, plot2]

Show[plot2, plot1]


The simplest solution is to set the option explicitly in Show:

Show[plot1, plot2, PlotRange -> All]


• +1 for the simple explanation. Does (2) applies to 3D graphics? – Sigur Jun 2 '14 at 23:42
• @Sigur I don't think so. – Szabolcs Jun 3 '14 at 12:10