0
$\begingroup$

This question already has an answer here:

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.

$\endgroup$

marked as duplicate by MarcoB, m_goldberg, user9660, Öskå, Edmund Mar 26 '16 at 11:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 6
    $\begingroup$ This question (Plot with Epilog doesn't show up in Show) most directly duplicates your issue; a full explanation can be found here: Plot Option Precedence while combining Plots with Show[]. More specifically, what you are trying to do seems more easily accomplished using the Filling option of Plot as Kay showed below. $\endgroup$ – MarcoB Mar 24 '16 at 19:49
  • $\begingroup$ @MarcoB so the answer is: to move all the Epilog in the first graphic displayed by Show $\endgroup$ – Fabio Mar 24 '16 at 20:26
  • 1
    $\begingroup$ Yep, pretty much, or possibly better, to add the objects that you were trying to show with Epilog to a separate Graphics expression inside Show, i.e. Show[plot1, plot2, Graphics[epilogstuff]]. $\endgroup$ – MarcoB Mar 24 '16 at 20:29
  • $\begingroup$ MarcoB, I've tried your suggestion, but still nothing appears $\endgroup$ – Fabio Mar 25 '16 at 12:34
  • $\begingroup$ seeing your edit, the issue is exactly about option precedence. you can not have two epilogs, only the first one is used. You need to put Epilog -> {Inset[shadow2], Inset[shadow]} either in the first Plot or as an option to Show $\endgroup$ – george2079 Mar 25 '16 at 15:36
6
$\begingroup$

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

$\endgroup$
3
$\begingroup$

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

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.