Re: Drawing Order of Grid Lines

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue Aug 16 2011 - 07:21:24 MDT

Hi again Bruce,

I realized there was a slightly better way to draw these two plots, especially if you need
to resize or panel them later.

You can use "gsn_add_annotation" to add the plot without lines to the plot with lines.
Unlike "overlay", this will keep the grid lines *under* the other plot, because
gsn_add_annotation isn't trying to manage the draw order of anything.

Also, the two plots are now "connected" to each other, so if you resize the base
plot, the annotation plot will stay with it.

Here's the same script again, with the addition of gsn_add_annotation.

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin
 x = new(1000,integer)
 do i=0,dimsizes(x)-1
   x(i) = rand()
 end do
 x = x/320

 wks = gsn_open_wks("eps","zhisto")
 gsn_define_colormap(wks,"temp1")

 res = True

 res@gsnMaximize = True
 res@gsnFrame = False
 res@gsnDraw = False

 res@gsnPaperOrientation = "portrait"

;---Create plot without X/Y grid lines
 plot_wo_grid = gsn_histogram(wks,x,res)

;---Create plot with X/Y grid lines
 res@tmXMajorGrid = True
 res@tmYMajorGrid = True
 res@tmXMajorGridLineDashPattern = 2
 res@tmYMajorGridLineDashPattern = 2

 plot_w_grid = gsn_histogram(wks,x,res)

;
; Add plot without lines as annotation of plot with lines.
;
; This will put the plot without lines on top of the one with lines. The
; default behavior of this function is that the two plots are
; centered. Since they are both already the same size, we don't have to
; set any additional resources.
;
 annoid = gsn_add_annotation(plot_w_grid,plot_wo_grid,False)

;---Drawing the base plot will draw base plot and annotation plot.
 draw(plot_w_grid)
 frame(wks)
end

--Mary

On Aug 12, 2011, at 9:26 AM, Mary Haley wrote:

> Hi Bruce,
>
> I fought with this a bit and couldn't get it to work. I tried creating a blank plot with grid lines, so
> I could overlay the histogram on top of that, but it still didn't work. I think NCL wants those
> tickmark grid lines to be drawn last no mater what.
>
> And no, unfortunately there's no "DrawOrder" resource for tickmarks. I created a ticket for this,
> NCL-1176.
>
> FYI, you can see all of the draw order resources at:
>
> http://www.ncl.ucar.edu/Applications/draworder.shtml
>
> Anyway, the only way I could get this to work was to draw the histogram twice: the first time
> with grid lines, and the second time without. I'm hoping Dave might have a better
> solution:
>
> ; histo_1.ncl
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> begin
> x = new(1000,integer)
> do i=0,dimsizes(x)-1
> x(i) = rand()
> end do
> x = x/320
> pfmt = "eps"
> pfmt = "x11"
> wks = gsn_open_wks(pfmt,"zhisto")
> gsn_define_colormap(wks,"temp1")
>
> res = True
>
> res@gsnFrame = False
>
> res@gsnPaperOrientation = "landscape"
>
> res@tmXMajorGrid = True
> res@tmXMajorGridLineDashPattern = 2
> res@tmYMajorGrid = True
> res@tmYMajorGridLineDashPattern = 2
>
> plot_w_grid=gsn_histogram(wks,x,res)
>
> delete(res@tmXMajorGrid)
> delete(res@tmXMajorGridLineDashPattern)
> delete(res@tmYMajorGrid)
> delete(res@tmYMajorGridLineDashPattern)
>
> plot_wo_grid=gsn_histogram(wks,x,res)
>
> frame(wks)
> end
>
> --Mary
>
>
> On Aug 11, 2011, at 3:32 PM, Lunde, Bruce N CIV NAVOCEANO, NP1 wrote:
>
>> Hello, I am drawing a histogram with grid lines turned on.
>> I wish the grid lines to be drawn underneath the boxes.
>> I have tried
>> res@tfPolyDrawOrder = "PostDraw"
>> but that does not seem to work.
>>
>> Are there options such as
>> tmGridDrawOrder = "PreDraw"
>> tmMajorGridDrawOrder = "PreDraw"
>> tmXMajorGridDrawOrder = "PreDraw"
>> etc. ??
>>
>> Thanks, Bruce
>>
>> Here is my basic code modifying one of your examples:
>>
>> ; histo_1.ncl
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> begin
>> x = new(1000,integer)
>> do i=0,dimsizes(x)-1
>> x(i) = rand()
>> end do
>> x = x/320
>> pfmt = "eps"
>> pfmt = "x11"
>> wks = gsn_open_wks(pfmt,"zhisto")
>> res = True
>> res@tmXMajorGrid = True
>> res@tmXMajorGridLineDashPattern = 2
>> res@tmYMajorGrid = True
>> res@tmYMajorGridLineDashPattern = 2
>>
>> res@tfPolyDrawOrder = "PostDraw" ;.. NOT SEEM TO HELP
>>
>> res@gsnPaperOrientation = "landscape"
>>
>> gsn_define_colormap(wks,"temp1")
>> plot=gsn_histogram(wks,x,res)
>> end
>> _______________________________________________
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Aug 16 07:21:33 2011

This archive was generated by hypermail 2.1.8 : Mon Aug 22 2011 - 08:13:37 MDT