# Does combining a plot and a region with Show override the region's options?

A few simple shapes:

lowercover = RegionDifference[Rectangle[{-2, -2}, {2, 0}], Disk[{0, 0}, 1]];
uppercover = RegionDifference[Rectangle[{-2, 0}, {2, 2}], Disk[{0, 0}, 1]];
square1 = Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}];
square2 = Polygon[{{0.5, 0}, {1.5, 0}, {1.5, 1}, {0.5, 1}}];


When I do the following, Show ignores color options (the squares show as black) in the second and third objects:

Show[
Plot[None, {x, -2, 2}, PlotRange -> {{-1.05, 1.05}, {-1.05, 1.05}}],
Region[square1, BaseStyle -> {FrontFaceColor -> Blue}],
Region[square2, BaseStyle -> {FrontFaceColor -> Green}]]


Yet when I try this other example, Show honors the color options (shows blue and green) in the second and third objects:

Show[
Plot[None, {x, -2, 2}, PlotRange -> {{-1.05, 1.05}, {-1.05, 1.05}}],
Region[uppercover, BaseStyle -> {FrontFaceColor -> Blue}],
Region[lowercover, BaseStyle -> {FrontFaceColor -> Green}]]


Why is the behavior different?

(This is on 11.2)

ADDENDUM: The answers below are very helpful but I wanted to point out one one other surprising outcome:

blank = Graphics[{}, PlotRange -> {{0, 2}, {0, 1}}];
a = Polygon[{{0, 0}, {2, 0}, {2, 1}, {0, 1}}];
b = Polygon[{{1, 0}, {2, 0}, {2, 1}, {1, 1}}];
c = Polygon[{{-0.36, 0.21}, {-0.36, -0.21}, {0, -0.53}, {0.64, -0.37}, {0.64, 0.37}, {0, 0.53}}]
d = Polygon[{{-0.42, 0.24}, {-0.42, -0.24}, {0, -0.56}, {0.58, -0.33}, {0.58, 0.33}, {0, 0.56}}]
Show[blank, Region[RegionDifference[a, b], BaseStyle -> {FrontFaceColor -> Green}]]
Show[blank, Region[RegionDifference[c, d], BaseStyle -> {FrontFaceColor -> Green}]]


The first Show takes the color as a directive whereas the second takes it as an option and overrides it. Now, while this is surprising, the reason is pretty clear if you just evaluate the following:

RegionDifference[a, b]
RegionDifference[c, d]


The former returns a Boolean region while the latter returns a Polygon, and that's presumably why we get different outcomes. At one point, they both returned Boolean regions (or something equivalent), but I believe the update in RegionDifference for 11.2 has made the behavior diverge. So Show is very well-behaved. RegionDifference is still a a bit of a mystery to me!

• Comments are not for extended discussion; this conversation has been moved to chat.
– Kuba
Mar 23, 2018 at 7:11
• I would argue that the second one is the buggy behavior: Show[Graphics[{}, BaseStyle -> Orange, PlotRange -> 2], Region[square1, BaseStyle -> {FrontFaceColor -> Blue}], Region[square2, BaseStyle -> {FrontFaceColor -> Green}]], and compare with the version with uppercover and lowercover. Mar 23, 2018 at 7:16
• BaseStyle for Region is not only a final's Graphics' options but is also passed inside the structure. And the way it is used next to Polygon differs whether you use RegionDifference or simple region. Show still does not care about subsequent options. But Region has colorDirectives, polygon structure inside. See remark about PlotStyle/PlotMarkers in linked answer.
– Kuba
Mar 23, 2018 at 7:16
• @Kuba, I think there is at least reportable behavior here, but I'll leave voting to reopen to other people. Mar 23, 2018 at 7:22
• @J.M. let me be me then because I already wasted one reopen vote by opening/closing.
– Kuba
Mar 23, 2018 at 7:24

I'll use a simpler example for this demonstration.

blank = Graphics[{}, PlotRange -> {{0, 2}, {0, 1}}];

square1 = Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}];
square2 = Polygon[{{1, 0}, {2, 0}, {2, 1}, {1, 1}}];

square3 = RegionDifference[Rectangle[{0, 0}, {2, 1}], Rectangle[{1, 0}, {2, 1}]];
square4 = RegionDifference[Rectangle[{1, 0}, {3, 1}], Rectangle[{2, 0}, {3, 1}]];


Have a look:

{Show[blank, Region[square1, BaseStyle -> {FrontFaceColor -> Blue}],
Region[square2, BaseStyle -> {FrontFaceColor -> Green}]],
Show[blank, Region[square3, BaseStyle -> {FrontFaceColor -> Blue}],
Region[square4, BaseStyle -> {FrontFaceColor -> Green}]]} // GraphicsRow


Another test:

blank2 = Graphics[{}, BaseStyle -> {FrontFaceColor -> Pink},
PlotRange -> {{0, 2}, {0, 1}}];

{Show[blank2, Region[square1, BaseStyle -> {FrontFaceColor -> Blue}],
Region[square2, BaseStyle -> {FrontFaceColor -> Green}]],
Show[blank2, Region[square3, BaseStyle -> {FrontFaceColor -> Blue}],
Region[square4, BaseStyle -> {FrontFaceColor -> Green}]]} // GraphicsRow


Something screwy is going on with the option inheritance in the right side. Here's why.

Recall that feeding a Region[] object to Show[] will effectively convert it to a Graphics[] object:

{Head[Region[square3]], Head[Show[Region[square3]]]}
{Region, Graphics}


and I would say that something in the conversion is causing this. Peering at the InputForm[] ought to be illuminating:

Show[Region[square1, BaseStyle -> {FrontFaceColor -> Blue}]] // InputForm
Graphics[{Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}], {}},
{BaseStyle -> {FrontFaceColor -> RGBColor[0, 0, 1]},
BaseStyle -> {Hue[0.6, 0.3, 0.95]}}]


where we note that the conversion behaved as expected, with BaseStyle going as an option at the end, and thus subject to the usual inheritance behavior.

Now, for the other square:

Short[InputForm[tst = Show[Region[square3, BaseStyle -> {FrontFaceColor -> Blue}]]], 1]
Graphics[GraphicsComplex[{{1., 1.}, {1., 0.9285714285714285}, {1., 0.8571428571428571},
{1., 0.7857142857142857}, {1., 0.7142857142857142}, <<330>>,
{0.36186316312984096, 0.8086041639163778},
{0.3716571979394048, 0.42845000184937354}}, {<<2>>}], {<<1>>}]


As you might surmise from my use of Short[], the internal structure is long and complicated. The interesting part is what's inside the GraphicsComplex[] object:

Shallow[InputForm[Cases[tst, GraphicsComplex[pts_, rest_] :> rest, ∞]], 8]
{{Directive[{Hue[0.6, 0.3, 0.95], EdgeForm[{<< 1 >>}], EdgeForm[None],
Opacity[1], FrontFaceColor -> RGBColor[<< 3 >>], EdgeForm[None]}],
{Annotation[Polygon[{<< 616 >>}], "Geometry"], {Directive[Opacity[<< 1 >>]],
Point[{<< 337 >>}]}}}}


which finally reveals the reason for the behavior: FrontFaceColor -> Blue is being used as a directive, and not as an option. Because it is a directive, it is not subject to the inheritance rules for options.

It is a bit confusing, admittedly, but here is an even simpler demo of the same situation:

{Show[blank2, Graphics[{Polygon[{{0, 0}, {2, 0}, {2, 1}, {0, 1}}]},
BaseStyle -> FrontFaceColor -> RGBColor[0, 0, 1]]],
Show[blank2, Graphics[GraphicsComplex[{{0, 0}, {2, 0}, {2, 1}, {0, 1}},
{FrontFaceColor -> RGBColor[0, 0, 1],
Polygon[{1, 2, 3, 4}]}]]]} // GraphicsRow


• Thank you for this explanation! See my addendum above for my hypothesis of why my figures changed. Mar 23, 2018 at 13:56

BaseStyle for Region is not only a final's Graphics' option but is also passed inside the structure of Graphics' primitives.

The difference is that for RegionDifference it is included as Polygon's directive while for basic regions it is not.

This is why for basic regions this information is not preserved by Show. Because it only stays in options and they are ignored by Show in arguments past the first one.

See:

DeveloperPackedArrayForm @ ToBoxes @ Region[uppercover, BaseStyle -> Blue]


vs

ToBoxes @ Region[square1, BaseStyle -> Blue]

GraphicsBox[
TagBox[DynamicModuleBox[{...},
TagBox[{PolygonBox[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}], {}}, ...],
...],
...], {BaseStyle -> RGBColor[0, 0, 1],
BaseStyle -> {
Hue[0.6, 0.3, 0.95]}}]


So for RegionDifference BaseStyle behaves like e.g. PlotStyle for Plot. See remark about PlotStyle/PlotMarkers` in Plot Option Precedence while combining Plots with Show[]

• Thank you for this explanation! See my addendum above for my hypothesis of why my figures changed. Mar 23, 2018 at 13:56