0

I wonder why I cannot see the second inset by using this code

shadow = Rasterize[
   Plot[x, {x, 0, 1}, Filling -> Bottom, MeshShading -> None, 
    MeshStyle -> None, Axes -> None, PlotStyle -> None, 
    PlotRange -> {{0, 1}, {0, 1}}, PlotRangePadding -> 0, 
    ImagePadding -> {{20, 20}, {20, 20}}], Background -> None];
shadow2 = 
  Rasterize[
   Plot[1 - x, {x, 0, 1}, Filling -> Bottom, MeshShading -> None, 
    MeshStyle -> None, Axes -> None, PlotStyle -> None, 
    PlotRange -> {{0, 1}, {0, 1}}, PlotRangePadding -> 0, 
    ImagePadding -> {{20, 20}, {20, 20}}], Background -> None];
Show[
 Plot[x, {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1}}, 
  Epilog -> Inset[shadow]],
 Plot[1 - x, {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1}}, 
  Epilog -> Inset[shadow2]],
 PlotRangePadding -> 0, ImagePadding -> {{20, 20}, {20, 20}}
 ]

Thanks, for the information. enter image description here

This question has nothing to do with

Plot Option Precedence while combining Plots with Show[]

since my problem is specific about superposition of graphs by using insets and not about the option precedence. My graphs should graphically superimpose since they have been created with transparency. Note if one moves both the insets to an Epilog-> in Show[] the wanted result is displayed correctely.

Fabio
  • 1,357
  • 6
  • 13

2 Answers2

6

I just shortened your code a bit, is this what you were searching for? Though it's not directly the answer to your question...

pl[a_] := Plot[a, {x, 0, 1}, Filling -> Bottom];
Show[pl[x], pl[1 - x]]

enter image description here

Kay
  • 1,035
  • 7
  • 19
3

Looking at your existing code, a few suggestions present themselves:

  1. Do not rasterize the shadows; you gain nothing by it.
  2. Place plot options that you want to apply to all plots within Show, not within each plot.
  3. Remove redundant options.

If you do that, then you are left with:

shadow = Plot[x, {x, 0, 1}, Filling -> Bottom];
shadow2 = Plot[1 - x, {x, 0, 1}, Filling -> Bottom];

Show[
 shadow, shadow2,
 Plot[x, {x, 0, 1}],
 Plot[1 - x, {x, 0, 1}],     
 PlotRange -> {{0, 1}, {0, 1}}, PlotRangePadding -> 0, ImagePadding -> {{20, 20}, {20, 20}}
]

But now you realize that you are duplicating your efforts for no gain! The shadow* plots already do all you need:

Show[
 shadow, shadow2,
 PlotRange -> {{0, 1}, {0, 1}}, PlotRangePadding -> 0, 
 ImagePadding -> {{20, 20}, {20, 20}}
]

The you realize that you do not need to use Show here at all: you can simply Plot two functions at once:

Plot[
 {x, 1 - x}, {x, 0, 1},
 Filling -> Bottom
]

two colors

This is not yet what you wanted, though, because Plot automatically colors the two functions differently. We need to tell it to use the same color for both plots. We can do that by specifying a single PlotStyle directive to use for all plots; in particular, we will indicate that we want to use the first of the standard indexed colors (ColorData[97]), i.e. ColorData[97][1]:

Plot[
 {x, 1 - x}, {x, 0, 1},
 Filling -> Bottom,
 PlotStyle -> ColorData[97][1]
]

one color

MarcoB
  • 67,153
  • 18
  • 91
  • 189