Re: polyline can't see over filled contour

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri Mar 04 2011 - 08:57:30 MST

Hi John,

When you call gsn_polyline, the line gets drawn right at that moment. If you then have other calls that draw some plots, they will be drawn on top of this line.

If you want to have the line drawn on top of the plot, use "gsn_add_polyline" instead. This causes the line to be attached to the plot, and it should be attached to the top of the plot's elements (unless you set tfPolyDrawOrder to "Predraw" or "Postdraw")

It's called exactly the same way, except it's a function and you need to use a unique variable every time you call it.

Try changing this loop:

> do while ( nm .lt. nrow )
> np = floattointeger( data(nm,0) )
> x = new(np,"float")
> y = new(np,"float")
>
> nstart = nm+1
> x(0) = data(nstart,0)
> y(0) = data(nstart,1)
> do i= nstart+1, np+nm
> x(i -nstart) = data(i, 0)
> y(i-nstart) = data(i,1)
> end do
> gsn_polyline(wks,plot2,x,y,res_poly)
>
> nm = nm+np+1
>
> delete(x)
> delete(y)
> end do

to this:

  line = new(nrow,graphic) ; this will be your array to hold each attached line.
> do while ( nm .lt. nrow )
> np = floattointeger( data(nm,0) )
> x = new(np,"float")
> y = new(np,"float")
>
> nstart = nm+1
> x(0) = data(nstart,0)
> y(0) = data(nstart,1)
> do i= nstart+1, np+nm
> x(i -nstart) = data(i, 0)
> y(i-nstart) = data(i,1)
> end do
> line(nm) = gsn_add_polyline(wks,plot2,x,y,res_poly)
>
> nm = nm+np+1
>
> delete(x)
> delete(y)
> end do

The added polylines will get drawn only when you draw plot2, which you are already doing later in the code.

--Mary

On Mar 4, 2011, at 7:50 AM, John Hyun wrote:

> Dear all,
>
> I had draw polyline using gsn_polyline function for line countour plot and then overlay this plot to another filled contour plot .
>
> But strangely only contour line can see over this filled contour and polyline are below filled contours.
>
> As you can see in the attached picture, only line contour can see over filled and polyline ( coast line and political boundaries are
> under the filled contour so can't see. )
>
> Could anyone let me know how I can make this polyline can see over the filled contours ?
>
> The followings are major part of my ncl codes. Please check and let me know where should I fix.
>
> =========================================================================
> begin
> .....
> res = True
> res@mpProjection ="LambertConformal"
> res@mpLambertParallel1F = 30.0 ; two parallels
> res@mpLambertParallel2F = 60.0
> res@mpLambertMeridianF = 126.0
>
> --- define map area using Corners mode --
>
> res@gsnDraw = False
> res@gsnFrame = False
>
>
> ; First line contour plot
>
> res@cnInfoLabelOn = False
> res@cnLineLabelPlacementMode = "Constant"
> res@cnInfoLabelOrthogonalPosF = 0.07
> res@cnLineLabelInterval = 1
> res@cnMonoLineThickness = False
> res@cnFillOn = False
> res@cnLineLabelInterval = 2
>
> res@tfDoNDCOverlay = True
>
> plot2 = gsn_csm_contour_map(wks,P,res)
>
> ; read polygon data then draw polyline for coast line and political boundaries
> fname = "/root/high_korea_map.dat"
> nrow = numAsciiRow(fname)
> data = asciiread(fname, (/nrow, 2/), "float")
> nm = 0
>
> ; draw coast line and political boundaries for plot2
>
> res_poly = True
> res_poly@gsEdgesOn = True ; draw border around polygons
> res_poly@gsEdgeColor = "black"
> res_poly@gsFillColor = -1
> res_poly@gsLineColor = "Black" ; color of lines
> res_poly@gsLineThicknessF = 1.0
>
> do while ( nm .lt. nrow )
> np = floattointeger( data(nm,0) )
> x = new(np,"float")
> y = new(np,"float")
>
> nstart = nm+1
> x(0) = data(nstart,0)
> y(0) = data(nstart,1)
> do i= nstart+1, np+nm
> x(i -nstart) = data(i, 0)
> y(i-nstart) = data(i,1)
> end do
> gsn_polyline(wks,plot2,x,y,res_poly)
>
> nm = nm+np+1
>
> delete(x)
> delete(y)
> end do
>
> ; second filled contour for precipitation
> res1 = True
> res1@mpLimitMode = "Corners" ; limit map via lat/lon
> res1@mpLeftCornerLatF = 32.1631622 ; map area
> res1@mpRightCornerLatF = 43.0738945 ; latitudes
> res1@mpLeftCornerLonF = 121.802254 ; and
> res1@mpRightCornerLonF = 132.368515 ; longitudes
>
> res1@gsnDraw = False ; don't draw the plots now
> res1@gsnFrame = False ; or advance the frame
> res1@cnFillDrawOrder ="PreDraw"
> res1@cnFillOn = True
> res1@tfDoNDCOverlay = True
>
> plot3 = gsn_csm_contour_map(wks,Rain,res1)
>
> draw(plot3)
> draw(plot2)
> frame(wks)
>
> end
> ===================================================================================
>
> Best regards,
>
> John Hyun
>
>
> <Surface.000001.png>_______________________________________________
> 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 Fri Mar 4 08:57:35 2011

This archive was generated by hypermail 2.1.8 : Mon Mar 07 2011 - 15:20:58 MST