I have a ListPlot of 100 data points in the range of 0 and 1. Now I'm trying to find a way to overlay (four) rectangles onto the ListPlot in 0.25 steps horizontally. Essentially I just have BinLists and try to visualize the Bins on the ListPlot with rectangles.

I drew a nice little picture with paint (since I can't draw it in mathematica yet :)) which hopefully makes it a little more clearer..I only drew three rectangles..

enter image description here

It seems somehow complicated to me and I don't get it to work (except with paint ^^), can someone help me out?

  • $\begingroup$ You might want to take a look at GridLines and its option GridLinesStyle :) I don't have Mathematica right now but by playing around with these two you should be able to have what you want :) $\endgroup$ – Öskå Apr 19 '14 at 19:47
  • 1
    $\begingroup$ Try Epilog->{Rectangle[...]} too. $\endgroup$ – Kuba Apr 19 '14 at 20:31

1. Use Epilog:

ListPlot[RandomInteger[50, 100],
 Epilog -> {EdgeForm[{Thick, Gray}], Opacity[.2], Blue, 
     Rectangle @@@ Thread[{Thread[{0, Range[0, 40, 10]}], 
                           Thread[{100, Range[10, 50, 10]}]}]}]
(* or use `MapThread[Rectangle, {Thread[{0, Range[0, 40, 10]}], 
  Thread[{100, Range[10, 50, 10]}]}]` instead of `Rectangle@@@Thread[...]`  *)

enter image description here

2. Use GridLines:

ListPlot[RandomInteger[50, 100], GridLines -> {{100}, Range[0, 50, 10]}]

enter image description here

3. Overlay ListPlot with Histogram using a constant height specification:

data = RandomInteger[50, 100];
bins = Range[0, 50, 10];
(* use a constant function for the third argument of `Histogram` *)
Show[ListPlot[data], Histogram[data, {bins}, 100 & /@ # &, BarOrigin -> Left, 
    ChartStyle -> Opacity[.3]]]

enter image description here

  • $\begingroup$ Works! Thank you $\endgroup$ – holistic Apr 20 '14 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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