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

Home » Public Forums » archive » Re: Problems with plotting in histogram mode
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: Problems with plotting in histogram mode [message #49677] Tue, 08 August 2006 07:58
liamgumley is currently offline  liamgumley
Messages: 74
Registered: June 2005
Member
The PSYM=10 histogram plotting technique is notoriously unreliable. You
might like to try this histogram plotting routine from my book instead.

PRO HIST_PLOT, DATA, MIN=MIN_VALUE, MAX=MAX_VALUE, $
BINSIZE=BINSIZE, NORMALIZE=NORMALIZE, FILL=FILL, $
_EXTRA=EXTRA_KEYWORDS

;- Check arguments
if n_params() ne 1 then message, 'Usage: HIST_PLOT, DATA'
if n_elements(data) eq 0 then message, 'DATA is undefined'

;- Check keywords
if n_elements(min_value) eq 0 then min_value = min(data)
if n_elements(max_value) eq 0 then max_value = max(data)
if n_elements(binsize) eq 0 then $
binsize = (max_value - min_value) * 0.01
binsize = binsize > ((max_value - min_value) * 1.0e-5)

;- Compute histogram
hist = histogram(float(data), binsize=binsize, $
min=min_value, max=max_value)
hist = [hist, 0L]
nhist = n_elements(hist)

;- Normalize histogram if required
if keyword_set(normalize) then $
hist = hist / float(n_elements(data))

;- Compute bin values
bins = lindgen(nhist) * binsize + min_value

;- Create plot arrays
x = fltarr(2 * nhist)
x[2 * lindgen(nhist)] = bins
x[2 * lindgen(nhist) + 1] = bins
y = fltarr(2 * nhist)
y[2 * lindgen(nhist)] = hist
y[2 * lindgen(nhist) + 1] = hist
y = shift(y, 1)

;- Plot the histogram
plot, x, y, _extra=extra_keywords

;- Fill the histogram if required
if keyword_set(fill) then $
polyfill, [x, x[0]], [y, y[0]], _extra=extra_keywords

END

Cheers,
Liam.
Practical IDL Programming
http://www.gumley.com/

harrisrj@mit.edu wrote:
> Hello,
>
> I'm having a bit of a problem with IDL's built in histogram mode (plot
> ... psym=10). I'm trying to plot 30 plots (using multiplot, [5,6],
> perhaps available in one of the astronomy libraries for IDL) and they
> each involve 32 bins. When I try to plot them, however, the bars seem
> to go too far, e.g. if one is centered over bin 5, then the bar will
> protrude out into bins 4 and 6. Has anyone experienced this/solved it?
> Any help is appreciated. Thanks.
>
> Robert Harris
[Message index]
 
Read Message
Previous Topic: Re: Reading columns of binary data
Next Topic: Reading in a postscript file into IDL

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

Current Time: Wed Oct 08 11:27:23 PDT 2025

Total time taken to generate the page: 0.01222 seconds