1
$\begingroup$

This question already has an answer here:

Given the following simple code:

With[{msm = RandomReal[{58., 62.}, 27]},
Manipulate[
 meanval = Mean[msm];
 dif = msm - meanval;
 var = variance[dif];
 sigma = Sqrt[var];
 ulnsigma := meanval + n*sigma;
 llnsigma := meanval - n*sigma;
 Show[
  Plot[{meanval, ulnsigma, llnsigma}, {x, 0, Length[msm] + 1}, 
   PlotStyle -> {Red, {Pink, Dashed}, {Pink, Dashed}}, 
   PlotRange -> {Min[msm]*0.99, Max[msm]*1.01}],
  ListLinePlot[msm, PlotMarkers -> Automatic, 
   PlotStyle -> {Thin, Dashed}]
  ],
 {{n, 1., "n-Sigma"}, {1, 3, 4, 5, 6}, ControlType -> PopupMenu},
 Initialization :> (
   variance[x_] := Total[x^2]/(Length[x] - 1))]
]

I have the problem, that Show scales the graph according to the first plot in the list, which is disturbing, because the other plots could eventually be out of range and not entirely visible... As you can see, I've also tried to "cheat" it with a PlotRange but I'm still not getting the wished results. I would have thought that Show should have an "autorange" option, so that it makes all the contained plots visible... or am I missing something? Here an example, where you cannot see the dashed limit-lines for values of n other that 1...

enter image description here enter image description here

$\endgroup$

marked as duplicate by MarcoB, Szabolcs, user9660, J. M. is away Jul 7 '16 at 14:55

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.

  • $\begingroup$ "...Show scales the graph according to the first plot in the list, which is disturbing, because the other plots could eventually be out of range and not entirely visible..." - yes, that's known behavior. $\endgroup$ – J. M. is away Jul 7 '16 at 14:02
  • $\begingroup$ @J.M. in my opinion it should be described as a "known problem" instead of "known behaviour" :-) . Thanks for the link (wasn't able to find it myself)! $\endgroup$ – Conrad Jul 7 '16 at 14:07
  • 1
    $\begingroup$ As you can see from the linked thread, the solution is Show[..., PlotRange -> All]. OK to mark as duplicate? In principle things can go wrong with this one too (as in showing too much), but that doesn't usually happen. $\endgroup$ – Szabolcs Jul 7 '16 at 14:16
  • 1
    $\begingroup$ I think the easy solution is to not use Show, but add the horizontal lines as Epilog items to your ListLinePlot. I'd work it up as an answer, but I'm pressed for time just now. $\endgroup$ – m_goldberg Jul 7 '16 at 14:48
  • 1
    $\begingroup$ If you use Epilog, look up InfiniteLine (@m_goldberg) $\endgroup$ – Szabolcs Jul 7 '16 at 15:20

Browse other questions tagged or ask your own question.