; File: histo.pro ; Author: Erik Brisson pro myhisto, xmin, xmax, nbins, y xspan = xmax - xmin bsize = float(xspan) / float(nbins) print, "bsize =", bsize h = histogram(y, min=xmin, max=xmax, binsize=bsize) x = xmin + (findgen(nbins)+0.5)*bsize for i=0, nbins-1 do begin print, i, x(i), h(i) end plot, psym=10, x, h ; optional stuff to fill in the two ends xextra = [xmin, xmin, xmin+(bsize/2.0)] hextra = [0, h(0), h(0)]; oplot, xextra, hextra xextra = [xmax-(bsize/2.0), xmax, xmax] hextra = [h(nbins-1), h(nbins-1), 0]; oplot, xextra, hextra end x = findgen(101) - 50 y = x * sin(x) xmin = -50 xmax = 50 nbins = 10 window, 0, retain=2, title='original function' plot, x, y window, 1, retain=2, title='myhisto' myhisto, xmin, xmax, nbins, y end