View Full Version : Gridlines and time-based abscissa

07-07-2008, 11:36 AM
I can put gridlines on my xy plots by specifying xticks, gridstyle, and ticklen. This works well until I change the abscissa to a DT structure; the lines disappear. Any suggestions?

07-08-2008, 03:58 PM
Using the slightly modified version of the Exampl 4 code in the PLOT documentation, I see the issue you are describing, but only for vertical grid lines (the horizontal grid lines are still drawn). Is this what you are seeing?

You could use PLOTS to draw your own grid lines, but this would be difficult to make generalized...

07-09-2008, 05:31 AM
that's exactly what i'm (not) seeing. using PLOTS would be time consuming, as it would be difficult to know where the time levels are occuring. I had a slightly similar problem with annotating !DT plots.

07-09-2008, 11:02 AM
Here is some sample code that may help you. I manually draw the X axis tickmarks/gridlines. The User Library routine GETTICK may be helpful to you, and it should be noted that the FOR loop at the bottom of the code below is essentially from $VNI_DIR/wave/lib/std/boxplot.pro, as that routine draws its own tick marks as well (as opposed to the default ticks displayed by PLOT).

See the attached screenshot for an example of the output.

Hope this helps!


;;Create plot with no X axis ticks or labels...
data = RANDOMU(seed,10)
PLOT, data, $
Title='2007 Monster Truck Sales', $
YTitle='Log Sales', $
YGridstyle=1, $
YTicklen=0.5, $
Xmargin=[10.5,3], $
Xgridstyle=1, $
Xticklen=0.5, $
XTicks=1, $
XTickname=[' ',' '], $
Xstyle=1, $
Xminor=-1, $
Ystyle=1, $
Ymargin=[5,2] , $

;;Figure out where the ticks should go on the X axis...
ticks = (!X.Window(1) - !X.Window(0)) * !D.X_Size / (!D.X_Ch_Size+2)
xcount = N_ELEMENTS(data)
IF xcount LT ticks THEN BEGIN
ticklocation = FINDGEN(xcount+1)
ticklocation = GETTICK(0, xcount, ticks=15) ;;GETTICK is in the User Lib
ticklocation(0) = 0

;;Set up the spacing of how far off, vertically, the ticks are from the
;;X axis...
dataMin = MIN(data)
dataMax = MAX(data)
gap = (dataMin - dataMax) / 50.0

;;Set up some basic plotting parameters for the upcoming PLOTS call to
;;draw the tick marks...
IF N_ELEMENTS(yrange) NE 2 THEN yrange = [datamin-gap, datamax+gap]
thick = 1
yoffset = 0.02

;;Convert tick locations to Normalized coordinates...
exact = CONVERT_COORD(ticklocation, $
FLTARR(N_ELEMENTS(ticklocation))+yrange(0)+yoffset/2, $
/Data, /To_Normal)

;;Create DT variables for the abscissa...
start = VAR_TO_DT(2007,1,1)
dates = DTGEN(start, 10, Month=1)
months = MONTH_NAME(dates)

;;Plot the tick marks and the labels...
FOR j=0, N_ELEMENTS(ticklocation)-2 DO BEGIN
;;This PLOTS call just plots the tick marks, but not grid lines
;PLOTS, [exact(0,j),exact(0,j)], [exact(1,j),exact(1,j)-yoffset], $
; /Normal, Thick=thick
;;This PLOTS call makes the tick marks as vertical grid lines
tickLoc = CONVERT_COORD(exact(0,j), !Y.Window(0), /Normal, /To_Data)
PLOTS, [tickLoc(0),tickLoc(0)], [!Y.crange(0),!Y.crange(1)], $
/Data, Thick=thick, Linestyle=1
points = CONVERT_COORD(exact(0,j), !Y.Window(0), /Normal, /To_Device)
XYOUTS, points(0,0)+2, points(1,0)-(!D.Y_Ch_Size)*3.25, $
months(j), /Device, Align=0.5, Orientation=90, Charsize=0.75


07-15-2008, 06:23 AM
it works great!