1

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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Conrad
  • 723
  • 4
  • 10
  • "...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. – J. M.'s missing motivation Jul 07 '16 at 14:02
  • @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)! – Conrad Jul 07 '16 at 14:07
  • 1
    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. – Szabolcs Jul 07 '16 at 14:16
  • @Szabolcs Yes, it's indeed a duplicate, sorry... – Conrad Jul 07 '16 at 14:21
  • No need to be sorry, this stuff is not easy to find. Just wanted to make sure that it solves your problem before voting. – Szabolcs Jul 07 '16 at 14:29
  • 1
    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. – m_goldberg Jul 07 '16 at 14:48
  • If you want to pursue m_goldberg's approach, you can adapt some of the solutions here to make horizontal lines. – J. M.'s missing motivation Jul 07 '16 at 14:53
  • 1
    If you use Epilog, look up InfiniteLine (@m_goldberg) – Szabolcs Jul 07 '16 at 15:20

0 Answers0