;+ ; NAME: loghist2d ; PURPOSE: ; Wrapper for hist2d which allows logarithmic bins and some other options ; ; INPUTS: ; KEYWORDS: ; OUTPUTS: ; ; HISTORY: ; Began 2007-03-21 11:15:44 by Marshall Perrin ;- function loghist2d, v1o, v2o, $ log1=log1, log2=log2, nbins1=nbin1, nbins2=nbin2,$ bin1=bin1o,bin2=bin2o,$ binval1=binval1,binval2=binval2,$ max1=max1o,min1=min1o, max2=max2o,min2=min2o,$ plot=plot,stop=stop,$ xtitle=xtitleo,ytitle=ytitleo,$ scalemax=scalemax,$ _extra=_extra if ~(keyword_set(scalemax)) then scalemax = n_elements(v1o) ; ------ 1 ------ if keyword_set(log1) then begin ; convert to log coords v1=alog10(v1o) max1 = alog10(max1o) min1 = alog10(min1o) uv = uniqvals(v1) bin1 = uv[1]-uv[0] if keyword_set(bin1o) then begin ; HACK preserve number of bins, not bin size, when log-ifying nbin_lin = (max1o-min1o)/(bin1o) + 1 bin1 = (max1-min1)/(nbin_lin-1) end xtitle="Log ( "+xtitleo+" )" endif else begin v1=v1o & max1=max1o & min1=min1o & bin1 = bin1o xtitle=xtitleo endelse if ~(keyword_set(bin1)) and keyword_set(nbin1) then bin1 = (max1-min1)/(nbin1-1) ; ------ 2 ------ if keyword_set(log2) then begin ; convert to log coords v2=alog10(v2o) max2 = alog10(max2o) min2 = alog10(min2o) uv = uniqvals(v2) bin2 = uv[1]-uv[0] if keyword_set(bin2o) then begin ; HACK preserve number of bins, not bin size, when log-ifying nbin_lin = (max2o-min2o)/(bin2o) + 1 bin2 = (max2-min2)/(nbin_lin-1) end ytitle="Log ( "+ytitleo+" )" endif else begin v2=v2o & max2=max2o & min2=min2o & bin2 = bin2o ytitle=ytitleo endelse if ~(keyword_set(bin2)) and keyword_set(nbin2) then bin2 = (max2-min2)/(nbin2-1) min1=min1-bin1*0.5 ; offset to center bins and prevent edge effects max1=max1+bin1*0.49 ; offset to center bins and prevent edge effects min2=min2-bin2*0.5 ; offset to center bins and prevent edge effects max2=max2+bin2*0.49 ; offset to center bins and prevent edge effects h = hist_2d(v1,v2, $ max1=max1,min1=min1, max2=max2,min2=min2,$ bin1=bin1,bin2=bin2,$ _extra=_extra) if keyword_set(plot) then begin h1 = histogram(v1, max=max1,min=min1,bin=bin1,loc=loc1) h2 = histogram(v2, max=max2,min=min2,bin=bin2,loc=loc2) centers1 = loc1+bin1/2 if keyword_set(log1) then prcenters1 = (10.^centers1) else prcenters1=centers1 centers2 = loc2+bin2/2 if keyword_set(log2) then prcenters2 = (10.^centers2) else prcenters2=centers2 prcenters1 = sigfig(prcenters1,3) prcenters2 = sigfig(prcenters2,3) ; in terms of scaling, we really want to preserve the appparent flux. ; so: scalemaxprime = scalemax/n_elements(h) scalemaxprime = n_elements(v1)/n_elements(h)*10 imdisp,bytscl(h,0,scalemaxprime),/noscale,xr=[min1,max1],yr=[min2,max2],/axis,$ xtitle=xtitle,ytitle=ytitle,_extra=_extra,$ xtickv=centers1, xtickname=prcenters1,xticks=n_elements(centers1)-1,$ ytickv=centers2, ytickname=prcenters2,yticks=n_elements(centers2)-1 ;xtickname = replicate(' ',30), ytickname= replicate(blankstring(max(strlen(prcenters2))+3),30),$ ;for i=0L,n_elements(centers1)-1 do xyouts,centers1[i],!y.crange[0]- (!y.crange[1]-!y.crange[0])*0.1, prcenters1[i] ;for i=0L,n_elements(centers2)-1 do xyouts,!x.crange[0]- (!x.crange[1]-!x.crange[0])*0.1,centers2[i], prcenters2[i] end if keyword_set(stop) then stop return,h end