Strange Show Behavior

When attempting to overlay a Discrete Plot on a Histogram, no matter the order I pass each argument in Show, the Histogram stacks over the Discrete Plot. Is it possible to lay the DiscretePlot over the histogram instead?

• it would be much easier for us if you could post the code instead of the snapshot Commented Oct 7, 2020 at 8:22

If you want to show a histogram and compare it against a PDF, you need to specify the "Probability" (for discrete distributions) or "PDF" (for continuous ones) property to fit the two on top of each other. Otherwise the axes are going to disagree and one plot will swamp out the other:

data = RandomVariate[GeometricDistribution[1/2], 100];
Show[
Histogram[data, Automatic, "Probability"],
DiscretePlot[PDF[GeometricDistribution[1/2], x], {x, 0, Max[data]}],
PlotRange -> All
]


For continuous data:

data = RandomVariate[ExponentialDistribution[1/2], 100];
Show[
Histogram[data, Automatic, "PDF"],
Plot[PDF[ExponentialDistribution[1/2], x], {x, 0, Max[data]}],
PlotRange -> All
]


In Show, Plot options that are given later will override those given earlier. So, make sure your axes fit or do not draw them. There is another possibility. Overlay will simply draw one picture over another.

Here is an example:

d1 = RandomReal[{0, 1}, 100];
g1 = Histogram[d1]
g2 = Plot[30 Sin[2 Pi x], {x, 0, 1}]
Show[{g1, g2}]
Overlay[{g1, g2}]


• Overlay will almost never properly align the axes, though. Commented Oct 7, 2020 at 10:22