3
$\begingroup$

My goal is to overlay two graphics;gcdf and ghisto. But when I overlay graphics using Show[], my plot is cropped unexpectedly as fig2..How to modify code?

\[Lambda] = 5; n = 100;
gcdf = Plot[
   CDF[ExponentialDistribution[1/(\[Lambda]/n)], x], {x, 0, 1}];
ghisto = Histogram[
   RandomVariate[GeometricDistribution[\[Lambda]/n], n]/n, Automatic, 
   "CDF", ImageSize -> 200];

{ghisto, gcdf}

fig1) graphics to be overlayed

enter image description here

Show[ghisto, gcdf]

fig 2) plot is cropped unexpectedly

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ Please include definition for xn. $\endgroup$
    – Syed
    Feb 24 at 11:08
  • 4
    $\begingroup$ Use PlotRange -> {0, 1} or PlotRange -> All in your Plot. It is not automatically adapted when you combine two graphics with Show, hence the blue curve is shown exactly as in your first image (namely from ~0.93 to 1). $\endgroup$
    – Domen
    Feb 24 at 11:10
  • $\begingroup$ Thanks for pointing out the wrong point in the question and I've just edited question. And Thank you for your answer.I'm not sure about the behind rules for automatically cropping graphs, but thanks for your answer. As you pointed out, when I add PlotRange option,the plot show fully.gcdf = Plot[ CDF[ExponentialDistribution[1/([Lambda]/n)], x], {x, 0, 1}, PlotRange -> All]; $\endgroup$
    – Soon
    Feb 24 at 11:20

1 Answer 1

3
$\begingroup$
gcdf =
 Plot[CDF[ExponentialDistribution[1/(\[Lambda]/n)], x], {x, 0, 1},
  ImageSize -> Medium,
  PlotRange -> {{0, 1}, {0, 1}}];

ghisto = 
 Histogram[RandomVariate[GeometricDistribution[\[Lambda]/n], n]/n, Automatic, "CDF", 
  ImageSize -> Medium, 
  PlotRange -> {{0, 1}, {0, 1}}];

Show[ghisto, gcdf]

enter image description here

$\endgroup$

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