comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: histogram and binsize problems
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: histogram and binsize problems [message #34257 is a reply to message #34252] Thu, 27 February 2003 09:11 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Chad Bender (cbender@mail.astro.sunysb.edu) writes:

> I'm encountering some confusion using the histogram function when
> specifying the min, max, and binsize keywords.

Oh, right. I'm glad I'm not the only one this drives
crazy.

I spend several chapters in a book talking about this oddity
in Histogram, but I have never gotten around to writing a
wrapper for the command. (Which seems really odd to me.)

In any case, he is the relevant code from the program in
the book:

; Calculate the histogram.

histdata = Histogram(image, Binsize=binsize, Max=Max(image), $
Min=Min(image))

; Have to fudge the bins and histdata variables to get the
; histogram plot to make sense.

npts = N_Elements(histdata)
halfbinsize = binsize / 2.0
bins = Findgen(N_Elements(histdata)) * binsize + Min(image)
binsToPlot = [bins[0], bins + halfbinsize, bins[npts-1] + binsize]
histdataToPlot = [histdata[0], histdata, histdata[npts-1]]
xrange = [Min(binsToPlot), Max(binsToPlot)]

; Plot the histogram of the display image. Axes first.

Plot, binsToPlot, histdataToPlot, $ ; Fudged histogram and bin data.
Background=backcolor, $ ; Background color of the display.
Charsize=thisCharsize, $ ; Character size.
Color=axiscolor, $ ; The color of the axes.
Max_Value=max_value, $ ; The maximum value of the plot.
NoData=1, $ ; Draw the axes only. No data.
Position=histoPos, $ ; Position of the plot.
Title='Image Histogram', $ ; The title of the plot.
XRange=xrange, $ ; The X data range.
XStyle=1, $ ; Exact axis scaling.
XTickformat='(I6)', $ ; Format of the X axis annotations.
XTitle='Image Value', $ ; The title of the X axis.
YMinor=1, $ ; One minor tick mark on X axis.
YRange=[0,max_value], $ ; The Y data range.
YStyle=1, $ ; Exact axis scaling.
YTickformat='(I6)', $ ; Format of the Y axis annotations.
YTitle='Pixel Density', $ ; The title of the Y axis.
_Extra=extra ; Pass any extra PLOT keywords.

; Overplot the histogram data in the data color.

OPlot, binsToPlot, histdataToPlot, PSym=10, Color=dataColor

; Make histogram boxes by drawing lines in data color.

FOR j=1L,N_Elements(bins)-2 DO BEGIN
PlotS, [bins[j], bins[j]], [!Y.CRange[0], histdata[j] < max_value], $
Color=dataColor
ENDFOR

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Is PDF the only help option in 5.6?
Next Topic: Matrix op speaks. Computer programmers needed to build matrix.

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 20:22:15 PDT 2025

Total time taken to generate the page: 0.48298 seconds