Michael Wallace writes:
> Okay, another object graphics question for everyone. Is there an easy
> way to shift a histogram over such that the bars are left justified with
> the data point rather than having the bars centered on the data point?
>
> I realize that I could shift the data itself and then draw the
> histogram, but there's a voice in the back of my mind that tells me
> "you're gonna shoot yourself in the foot, kid." Is there some other way
> to left justify the plot?
I thought the whole point of object graphics was that
you could do anything you wanted to do if you were
willing to spend enough time with inadequate documentation
to do it?
Cheers,
David
P.S. I don't have any ideas about how to do this in
object graphics. About a fourth of my book is about
how to do it in direct graphics. Presumably some of
those techniques could be extended to object graphics.
Here is the relevant part of the code:
; Calculate the histogram.
histdata = Histogram(image, Binsize=binsize, Max=Max(image), $
Min=Min(image))
; Have to fudge the bins and histdata variables to get the
; histogram plot to make sense.
npts = N_Elements(histdata)
halfbinsize = binsize / 2.0
bins = Findgen(N_Elements(histdata)) * binsize + Min(image)
binsToPlot = [bins[0], bins + halfbinsize, bins[npts-1] + binsize]
histdataToPlot = [histdata[0], histdata, histdata[npts-1]]
xrange = [Min(binsToPlot), Max(binsToPlot)]
; Plot the histogram of the display image. Axes first.
Plot, binsToPlot, histdataToPlot, $
Background=backcolor, $
Charsize=thisCharsize, $
Color=axiscolor,
Max_Value=max_value, $
NoData=1, $
Position=histoPos, $
Title='Image Histogram', $
XRange=xrange, $
XStyle=1, $
XTickformat='(I6)', $
XTitle='Image Value', $
YMinor=1, $
YRange=[0,max_value], $
YStyle=1, $
YTickformat='(I6)', $
YTitle='Pixel Density', $
_Extra=extra
; Overplot the histogram data in the data color.
OPlot, binsToPlot, histdataToPlot, PSym=10, Color=dataColor
; Make histogram boxes by drawing lines in data color.
FOR j=1L,N_Elements(bins)-2 DO BEGIN
PlotS, [bins[j], bins[j]], [!Y.CRange[0], histdata[j] < max_value], $
Color=dataColor
ENDFOR
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|