Re: Histrogram plot in IDL using cgHistoplot [message #76561] |
Wed, 15 June 2011 07:05 |
Sasha Singh
Messages: 13 Registered: November 2010
|
Junior Member |
|
|
On Jun 14, 4:26 pm, Jeremy Bailin <astroco...@gmail.com> wrote:
> I would use value_locate to bin the data into your unequal bins, and then use judicious use of xticks, xtickv and xtickname to get the labels right. Something like this:
>
> ; Create some data that has the correct distribution. Presumably
> ; you don't need to do this since you already have your data!
> data = [randomu(seed,11)*3, 3+randomu(seed, 16)*3, 6+randomu(seed, 5)*4, $
> 10+randomu(seed,3)*10, 20+randomu(seed,4)*20, 40+randomu(seed,2)*20]
>
> ; Specify where the bin edges are
> bin_edges = [0,3,6,10,20,40,60]
> nbins = n_elements(bin_edges)-1
>
> ; Map your data onto the bins, so values between 0 and 3 become "0",
> ; values between 3 and 6 become "1", etc.
> data_bins = value_locate(bin_edges, data)
>
> ; Create an array with each bin edge duplicated for labelling
> labelnums = rebin(1 # bin_edges, 2, nbins+1, /sample)
> ; And create the label strings
> labels = string(labelnums[1:2*nbins], format='(%"%0d - %0d")')
>
> ; Finally create the histogram
> cghistoplot, data_bins, xrange=[0,nbins], xticks=nbins-1, $
> xtickv=0.5+indgen(nbins), xtickname=labels
>
> -Jeremy.
Thank you. It works like a charm. The plot looks awesome :)
Sasha.
|
|
|
Re: Histrogram plot in IDL using cgHistoplot [message #76566 is a reply to message #76561] |
Tue, 14 June 2011 13:26  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
I would use value_locate to bin the data into your unequal bins, and then use judicious use of xticks, xtickv and xtickname to get the labels right. Something like this:
; Create some data that has the correct distribution. Presumably
; you don't need to do this since you already have your data!
data = [randomu(seed,11)*3, 3+randomu(seed, 16)*3, 6+randomu(seed, 5)*4, $
10+randomu(seed,3)*10, 20+randomu(seed,4)*20, 40+randomu(seed,2)*20]
; Specify where the bin edges are
bin_edges = [0,3,6,10,20,40,60]
nbins = n_elements(bin_edges)-1
; Map your data onto the bins, so values between 0 and 3 become "0",
; values between 3 and 6 become "1", etc.
data_bins = value_locate(bin_edges, data)
; Create an array with each bin edge duplicated for labelling
labelnums = rebin(1 # bin_edges, 2, nbins+1, /sample)
; And create the label strings
labels = string(labelnums[1:2*nbins], format='(%"%0d - %0d")')
; Finally create the histogram
cghistoplot, data_bins, xrange=[0,nbins], xticks=nbins-1, $
xtickv=0.5+indgen(nbins), xtickname=labels
-Jeremy.
|
|
|