Drawing a Histogram Plot
QUESTION: I see that I can set the PSYM=10 keyword on the PLOT command to draw a histogram plot. But, uh, it doesn't look exactly like the histogram plot I was expecting. Is there something else I should know? I tried this.
IDL> data = RandomU(5L, 200)*20 IDL> Plot, Histogram(data, BINSIZE=1.0), PSYM=10
And I got this result. I don't know. The ends are funny, and the data seems to be about half a bin out of align with the axis annotation. Can you help?
![]() |
| This a normal histogram plot in IDL. |
![]()
ANSWER: Well, unfortunately, this is about as good as IDL can do out of the box. If you want something more, you have to write it. It's not difficult, but it has to be done.
I've written a short program that works for my purposes. It is called HISTOPLOT. With the same data, you call it like this.
IDL> Histoplot, data, BINSIZE=1.0
These commands will produce a plot like this.
![]() |
| This is what can be done with the HISTOPLOT command from the Coyote Library. |
I usually prefer to fill the histogram bars, like this.
IDL> Histoplot, data, BINSIZE=1.0, /FILL
![]() |
| The bars of the histogram plot are filled. |
The HISTOPLOT command has many, many options. You can use different colors, different fill patterns, etc. Here is an example of some of the things that can be done.
IDL> data = RandomU(5L, 200)*20
IDL> !P.Multi = [0, 2, 2]
IDL> Histoplot, data, BINSIZE=1.0
IDL> Histoplot, data, BINSIZE=1.0, /FILL, POLYCOLOR=['charcoal', 'dodger blue']
IDL> Histoplot, data, BINSIZE=1.0, /LINE_FILL, $
POLYCOLOR=['charcoal', 'dodger blue'], ORIENTATION=[45, -45]
IDL> Histoplot, data, BINSIZE=1.0, /FILL, POLYCOLOR='sky blue'
IDL> moredata = RandomU(3L, 80)*20
IDL> Histoplot, moredata, BINSIZE=1.0, /FILL, POLYCOLOR='royal blue', /OPLOT
IDL> !P.MULTI = 0
The figure below is produced when you execute the commands above.
![]() |
| The HISTOPLOT command has many features. |
![]()
Copyright © 2007 David W. Fanning
Original Article: 20 November 2007
Updated: 4 February 2009



