pro plot_hist, dist, min=min, max=max, binsize=bin, _extra=ex, opsym=opsym $ , ocolor=ocolor, gaussfit=gaussfit, postscript=postscript $ , outfile=outfile, xhist=xh, yhist=h if ~keyword_set(bin) then bin = 1 ;;; Auto-size the bins. I found this at: ;;; http://www.fmrib.ox.ac.uk/analysis/techrep/tr00mj2/tr00mj2/node24.html if keyword_set(autobin) then begin sigma = stdev(d) nel = n_elements(dist) ;;; This is faster than nel^(-1./3) term = exp(-1./3 * alog(nel)) bin = 3.49 * sigma * term endif ;;; Set defaults if ~keyword_set(min) then min = min(dist) if ~keyword_set(max) then max = max(dist) ;;; Compute histogram h = histogram(dist, min=min, max=max, bin=bin) ;;; Compute histogram x values xh = fillarr(bin, min, max) + bin/2. ;;; Optionally, create a postscipt version if keyword_set(postscript) then begin if ~keyword_set(outfile) then outfile = './plot_hist.ps' psopen, outfile, xsize=7.5, ysize=7.5, /inch, /color endif plot, xh, h, ps=10, _extra=ex, xrange = [min, max] ;;; Oplot with optional symbols and colors if keyword_set(opsym) or keyword_set(ocolor) then $ oplot, xh, h, ps=opsym, col=ocolor ;;; Optionally fit a Gaussian and overplot the fit if keyword_set(gaussfit) then begin g = jjgaussfit(xh, h, a) xfine = makearr(1000, min, max) gfine = jjgauss(xfine, a) oplot, xfine, gfine, color=ocolor endif ;;; Close the postscript device if keyword_set(postscript) then psclose, /color end