Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
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 :) –  Öskå Apr 19 at 19:47
1  
Try Epilog->{Rectangle[...]} too. –  Kuba Apr 19 at 20:31

1 Answer 1

up vote 6 down vote accepted

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

share|improve this answer
    
Works! Thank you –  holistic Apr 20 at 12:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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