Re: panel plot with overlay and polyline

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu Mar 03 2011 - 06:34:45 MST

Hi again,

[Hope it's okay that I post back to ncl-talk. I think others would be
interested in the solution]

You're right the lines will be curved when you add them to the plot
using the lat,lon values in this way.

We have an example showing how you can get the straight lines *and*
still be able to attach them to the plot, using "gc_latlon".

Please see example 13 at:

http://www.ncl.ucar.edu/Applications/polyg.shtml

--Mary

On Mar 3, 2011, at 6:28 AM, Ufuk Utku Turuncoglu wrote:

> Hi Mary,
>
> It is working now but when i use the lat, lon values instead of NDC
> ones the domain box is plotted as curves not straight lines (see
> attached plot). I think that it is related with the projection
> because the only corner points are used but i am not sure. I try to
> use NDC values with gsn_add_polyline function but the box is not
> appear in this case. Is there any way to fix it?
>
> Thanks for your help,
> Best wishes,
>
> --ufuk
>
> On 3/3/11 2:58 PM, Mary Haley wrote:
>> Hi Ufuk,
>>
>> I think the problem is that you are drawing the line before you
>> draw the plot.
>> When you draw primitives (lines, polygons, markers) in NDC space,
>> they
>> can't be attached to a plot, so they actually get drawn at the moment
>> you call gsn_xxxx_ndc.
>>
>> I noticed that you're converting the lat,lon values to NDC. Is
>> there any reason
>> why you can't use the lat,lon values directly and call
>> gsn_add_polyline instead? This
>> way, the lines get attached to the plot, and whenever you the draw
>> the plot, the
>> lines should get drawn on top.
>>
>> dum = gsn_add_polyline(wks, map, (/
>> lon2d(0,0),lon2d(0,im-1),lon2d(jm-1,im-1), \
>> lon2d(jm-1,0),lon2d(0,0) /), (/
>> lat2d(0,0),lat2d(0,im-1),lat2d(jm-1,im-1), \
>> lat2d(jm-1,0),lat2d(0,0) /), res_line)
>>
>> --Mary
>>
>> On Mar 3, 2011, at 5:34 AM, Ufuk Utku Turuncoglu wrote:
>>
>>> Hi,
>>>
>>> I try to create a panel plot which contains both overlay and
>>> polyline
>>> structures but the polyline stay in the background of the plot or
>>> cross
>>> the panel plot labels. I try to fix the orders of the individual
>>> plots
>>> using different resource definitions such as tfPolyDrawOrder but
>>> it is
>>> not working. The plot must basically includes following,
>>>
>>> - plot surface temperature
>>> - overlay surface current vectors on it
>>> - add line to it to show the regional ocean model domain
>>> - put all of them into panel plot
>>>
>>> Any suggestions are welcome.
>>>
>>> Thanks,
>>>
>>> --ufuk
>>>
>>> --- The NCL script ---
>>>
>>> ; --------------------------------------------------------
>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>>> load "roms_func.ncl"
>>> ; --------------------------------------------------------
>>> begin
>>> ;--- parameters ---
>>> tstep = 1
>>>
>>> ;--- open grid file ---
>>> grid = addfile ("../in/med_grid.nc", "r")
>>>
>>> ;--- open output file ---
>>> nc = addfile ("../ocean_his.nc", "r")
>>>
>>> ;--- read variable ---
>>> vart = nc->temp(:,0,:,:)
>>> varu = u2rho(nc->u(tstep,0,:,:))
>>> varv = v2rho(nc->v(tstep,0,:,:))
>>>
>>> ;--- read coordinate variables (lat & lon) ---
>>> lat2d = grid->lat_rho
>>> lon2d = grid->lon_rho
>>>
>>> vart@lat2d = lat2d
>>> vart@lon2d = lon2d
>>> varu@lat2d = lat2d(::3,::3)
>>> varu@lon2d = lon2d(::3,::3)
>>> varv@lat2d = lat2d(::3,::3)
>>> varv@lon2d = lon2d(::3,::3)
>>>
>>> time = nc->ocean_time(tstep)
>>> date_arr = floattoint(ut_calendar(time, 0))
>>> date_str = sprinti("%d", date_arr(0,0))+"-"+sprinti("%2.2d",
>>> date_arr(0,1))+"-"+\
>>> sprinti("%2.2d", date_arr(0,2))
>>> ;+" "+sprinti("%2.2d", date_arr(0,3))
>>> +":"+sprinti("%2.2d",
>>> date_arr(0,4))
>>>
>>> ;--- create plot ---
>>> wks = gsn_open_wks ("pdf", "plot_"+sprinti("%4.4d", tstep))
>>> gsn_define_colormap(wks, "amwg_blueyellowred")
>>> i = NhlNewColor(wks,0.8,0.8,0.8)
>>>
>>> ;--- set plot resource ---
>>> res = True
>>> res@gsnDraw = False
>>> res@gsnFrame = False
>>> res@gsnMaximize = True
>>> res@cnFillOn = True
>>> res@cnFillMode = "RasterFill"
>>> res@cnLinesOn = False
>>> res@cnLineLabelsOn = False
>>> res@cnFillDrawOrder = "PreDraw"
>>> res@gsnSpreadColors = True
>>> res@gsnSpreadColorEnd = -3
>>> res@cnInfoLabelOn = False
>>> res@pmTickMarkDisplayMode = "Always"
>>> res@tmYRLabelsOn = False
>>> res@tmYROn = False
>>> res@tmXTLabelsOn = False
>>> res@tmXTOn = False
>>> res@tiXAxisString = "Longitude"
>>> res@tiYAxisString = "Latitude"
>>> res@tiXAxisFontHeightF = 0.015
>>> res@tiYAxisFontHeightF = 0.015
>>> res@tmLabelAutoStride = True
>>> res@lbLabelBarOn = False
>>>
>>> res@cnLevelSelectionMode = "ManualLevels"
>>> res@cnMinLevelValF = floor(min(vart))
>>> res@cnMaxLevelValF = ceil(max(vart))
>>> res@cnLevelSpacingF = 2
>>>
>>> ;--- mapping properties ---
>>> res@mpDataBaseVersion = "HighRes"
>>> res@mpProjection = "LambertConformal"
>>> res@mpOutlineDrawOrder = "PostDraw"
>>> res@mpGridAndLimbOn = False
>>> res@mpLambertParallel1F = grid->PLAT(0)
>>> res@mpLambertParallel2F = grid->PLAT(1)
>>>
>>> res@mpLimitMode = "Corners"
>>> res@mpLeftCornerLatF = grid->P1
>>> res@mpLeftCornerLonF = grid->P2
>>> res@mpRightCornerLatF = grid->P3
>>> res@mpRightCornerLonF = grid->P4
>>> res@mpLambertMeridianF = 16.0
>>>
>>> map = gsn_csm_contour_map(wks, vart(tstep,:,:), res)
>>>
>>> ;--- plot surface currents ---
>>> res_vec = True
>>> res_vec@gsnDraw = False
>>> res_vec@gsnFrame = False
>>> res_vec@pmTickMarkDisplayMode = "Always"
>>> res_vec@tmYRLabelsOn = False
>>> res_vec@tmYROn = False
>>> res_vec@tmXTLabelsOn = False
>>> res_vec@tmXTOn = False
>>> res_vec@tiXAxisFontHeightF = 0.015
>>> res_vec@tiYAxisFontHeightF = 0.015
>>>
>>> res_vec@vcRefAnnoSide = "Bottom"
>>> res_vec@vcRefAnnoJust = "BottomRight"
>>> res_vec@vcGlyphStyle = "CurlyVector"
>>> res_vec@vcRefAnnoOrthogonalPosF = -0.26
>>> res_vec@vcRefAnnoParallelPosF = 0.2
>>> res_vec@vcRefMagnitudeF = 0.05
>>> res_vec@vcRefLengthF = 0.03
>>> res_vec@vcMinDistanceF = 0.0
>>>
>>> plot = gsn_csm_vector(wks, varu(::3,::3), varv(::3,::3), res_vec)
>>> overlay(map, plot)
>>> draw(map)
>>>
>>> ;--- plot domain box ---
>>> dims = dimsizes(lat2d)
>>> im = dims(1)
>>> jm = dims(0)
>>> delete(dims)
>>>
>>> xbox = (/ lon2d(0,0),lon2d(0,im-1),lon2d(jm-1,im-1), \
>>> lon2d(jm-1,0),lon2d(0,0) /)
>>> ybox = (/ lat2d(0,0),lat2d(0,im-1),lat2d(jm-1,im-1), \
>>> lat2d(jm-1,0),lat2d(0,0) /)
>>>
>>> ;--- create box array ---
>>> x_out = new(dimsizes(xbox), "float")
>>> y_out = new(dimsizes(ybox), "float")
>>>
>>> res_line = True
>>> res_line@gsLineThicknessF = 2.0
>>> res_line@gsLineColor = "black"
>>> res_line@tfPolyDrawOrder = "PostDraw"
>>>
>>> datatondc(map, doubletofloat(xbox), doubletofloat(ybox), x_out,
>>> y_out)
>>> gsn_polyline_ndc(wks, x_out, y_out, res_line)
>>>
>>> ;--- create panel plot ---
>>> resP = True
>>> resP@gsnFrame = False
>>> resP@gsnPanelLabelBar = True
>>> resP@lbOrientation = "vertical"
>>> resP@pmLabelBarWidthF = 0.08
>>> resP@pmLabelBarHeightF = 0.40
>>> resP@pmLabelBarParallelPosF = 0.025
>>> resP@pmLabelBarOrthogonalPosF = 0.005
>>> resP@txFontHeightF = 0.012
>>> resP@gsnPanelFigureStringsFontHeightF = 0.012
>>> resP@gsnPanelFigureStrings= (/ date_str /)
>>>
>>> gsn_panel(wks, map, (/ 1,1 /), resP)
>>>
>>> frame(wks)
>>> end
>>>
>>>
>>> --
>>> This message has been scanned for viruses and
>>> dangerous content by MailScanner, and is
>>> believed to be clean.
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
> <plot_0001.pdf>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Mar 3 06:34:50 2011

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2011 - 10:00:25 MST