[ncl-talk] Add text and polymarkers on panel plots
Tabish Ansari
tabishumaransari at gmail.com
Fri Apr 26 07:16:00 MDT 2019
Hi Adam,
Thanks for pointing me to the right functions.
The gsn_add* functions throw a return value which needs to be stored in a
uniquely named variable each time.
As you can see in my script that I want to draw the polymarkers and attach
the text at every 10th grid point in the 2D-array (It's 120x120 grids).
I'm able to draw them using gsn_text and gsn_polymarker but not using the
corresponding gsn_add* functions. NCL doesn't give any error, but the
polymarkers and text aren't printed.
Here's my updated script:
*load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"load
"$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"beginncol = 11 ; COLUMNS
CORRESPOND TO THE 11 DAYS HEREdata =
readAsciiTable("/home/tabish/Emulation/EmulPreds_responsesurface_Run8.csv",
ncol, "float", 1); THIS WILL IGNORE THE 1ST ROW WHICH IS
HEADERdata at _FillValue = -999print("table read-in
successfully")printVarSummary(data);TRANSFORMING 14400X1 STRUCTURE TO
120X120 STRUCTURE FOR CONTOUR PLOTc=0a = new((/120,120/),float);MATRIX TO
HOLD VALUES FOR 24TH OCTb = new((/120,120/),float);MATRIX TO HOLD VALUES
FOR 30TH OCTdo i=0,119 do j=0,119 a(i,j) = data(c,3);THIS MATRIX STORES
VALUES FOR 24TH OCT b(i,j) = data(c,9);THIS MATRIX STORES VALUES FOR 30TH
OCT c = c+1 end doend do;ATTACHING 0-120% COORDINATE ARRAYS x =
ispan(0,119,1) y = ispan(0,119,1) a!0 = "x" a!1 = "y" a&x = x a&y =
y b!0 = "x" b!1 = "y" b&x = x b&y = y wks =
gsn_open_wks("x11","30OctRS_Beijing-IR_vs_Beijing-TP") ; Send graphics to
PNG file; Set up resources. res = True
res at gsnFrame = False ; Turn off so we can add markers
and text res at gsnMaximize = False res at cnFillOn =
True ; Turn on contour fill res at cnFillPalette =
"BlGrYeOrReVi200" ; Set color map ; res at cnFillPalette =
"WhiteBlue" ; Set color map res at tiYAxisFontHeightF = 0.018
res at tiXAxisFontHeightF = 0.018 res at tiYAxisString =
"Beijing(Pow+Tran)" res at pmTitleZone = 3 res at tiXAxisString =
"Beijing(Ind+Res)" ;res at cnFillMode = "RasterFill"
res at cnLinesOn = False res at lbOrientation = "vertical"
res at tmXBMajorOutwardLengthF = 0.0 ; draw tickmarks inward
res at tmXBMinorOutwardLengthF = 0.0 ; draw minor ticks inward
tmXTMajorOutwardLengthF = 0.0 ; draw tickmarks inward
res at tmXTMinorOutwardLengthF = 0.0 ; draw minor ticks inward
res at tmYLMajorOutwardLengthF = 0.0 ; draw tickmarks inward
res at tmYLMinorOutwardLengthF = 0.0 ; draw minor ticks inward
res at tmYRMajorOutwardLengthF = 0.0 ; draw tickmarks inward
res at tmYRMinorOutwardLengthF = 0.0 ; draw minor ticks inward;
plot1 = gsn_csm_contour(wks,a,res) ; Create filled contours plot2 =
gsn_csm_contour(wks,b,res) ; Create filled contours;---Draw text and
markers at data locations txres = True mkres
= True txres at txFontHeightF = 0.01 txres at txJust = "TopCenter" ;
text will be drawn under the marker mkres at gsMarkerIndex = 16 ; filled
circle;ROUNDING OFF THE PM2.5 VALUES FOR CLEAN PRINTINGa = round(a,0)b =
round(b,0)dumpoly1 = new(25,graphic)dumpoly2 = new(25,graphic)dumtext1 =
new(25,graphic)dumtext2 = new(25,graphic)c=0; counter variable for dummy
variables do j=0,100,20 do i=0,100,20 if((i.gt.0).and.(j.gt.0))
then print(i+","+j);
gsn_polymarker(wks,plot1,x(i-1),y(j-1),mkres); gsn_text(wks,plot1,"
~C~"+a(j-1,i-1),x(i-1),y(j-1),txres) dumpoly2(c) =
gsn_add_polymarker(wks,plot2,x(i-1),y(j-1),mkres) dumtext2(c) =
gsn_add_text(wks,plot2," ~C~"+b(j-1,i-1),x(i-1),y(j-1),txres) c =
c+1 end if end do end
do frame(wks);************************************************; create
panel;************************************************;resP =
True;resP at gsnPanelYWhiteSpacePercent =
0.0;gsn_panel(wks,(/plot1,plot2/),(/1,2/),resP) ; now draw as
one plotend*
Cheers,
Tabish
Tabish U Ansari
PhD student, Lancaster Environment Center
Lancaster Univeristy
Bailrigg, Lancaster,
LA1 4YW, United Kingdom
On Thu, 25 Apr 2019 at 19:00, Adam Phillips <asphilli at ucar.edu> wrote:
> Hi Tabish,
> If you are adding polymarkers/text to plots that are being paneled, you
> have to use the gsn_add_polymarker/gsn_add_text functions due to
> limitations with gsn_text/gsn_polymarker. See the documentation for the two
> add functions here:
> http://www.ncl.ucar.edu/Document/Graphics/Interfaces/gsn_add_text.shtml
>
> http://www.ncl.ucar.edu/Document/Graphics/Interfaces/gsn_add_polymarker.shtml
> Adam
>
> On Thu, Apr 25, 2019 at 11:21 AM Tabish Ansari <tabishumaransari at gmail.com>
> wrote:
>
>> Hi
>>
>> I'm able to add text and polymarkers of separate plots but not able to
>> panel them properly. The text and polymarkers are being added on the
>> original plots and then a panel is being displayed on top of that without
>> the text and polymarkers.
>>
>> Here's my code:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"load
>> "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"beginncol = 2 ; THE TWO
>> COLUMNS REPRESENT 2 DAYS: 24TH AND 30TH OCTOBERdata =
>> readAsciiTable("/home/tabish/Emulation/EmulPreds_responsesurface_Run2.csv",
>> ncol, "float", 1); THIS WILL IGNORE THE 1ST ROW WHICH IS
>> HEADERdata at _FillValue = -999print("table read-in
>> successfully")printVarSummary(data);TRANSFORMING 144X1 STRUCTURE TO 12X12
>> STRUCTURE FOR CONTOUR PLOTc=0a = new((/12,12/),float);MATRIX TO HOLD VALUES
>> FOR 24TH OCTb = new((/12,12/),float);MATRIX TO HOLD VALUES FOR 30TH OCTdo
>> i=0,11 do j=0,11 a(i,j) = data(c,0) b(i,j) = data(c,1) c = c+1 end doend
>> do;ROUNDING OFF THE PM2.5 VALUES FOR CLEAN PRINTINGa = round(a,0)b =
>> round(b,0);ATTACHING 0-120% COORDINATE ARRAYS x = ispan(0,110,10) y
>> = ispan(0,110,10) a!0 = "x" a!1 = "y" a&x = x a&y = y b!0 = "x" b!1 =
>> "y" b&x = x b&y = y wks = gsn_open_wks("x11","RS") ; Send graphics to
>> PNG file; Set up resources. res = True
>> res at gsnFrame = False ; Turn off so we can add markers
>> and text res at gsnMaximize = False res at cnFillOn =
>> True ; Turn on contour fill res at cnFillPalette = "amwg" ;
>> Set color map res at tiYAxisFontHeightF = 0.018 res at tiXAxisFontHeightF =
>> 0.018 res at tiYAxisString = "Near neighbourhood (Ind+pow+res+tran)"
>> res at pmTitleZone = 3 res at tiXAxisString = "Beijing
>> (Ind+pow+res+tran)" res at cnFillMode = "RasterFill"
>> res at cnLinesOn = False res at lbOrientation = "vertical"
>> res at tmXBMajorOutwardLengthF = 0.0 ; draw tickmarks inward
>> res at tmXBMinorOutwardLengthF = 0.0 ; draw minor ticks inward
>> tmXTMajorOutwardLengthF = 0.0 ; draw tickmarks inward
>> res at tmXTMinorOutwardLengthF = 0.0 ; draw minor ticks inward
>> res at tmYLMajorOutwardLengthF = 0.0 ; draw tickmarks inward
>> res at tmYLMinorOutwardLengthF = 0.0 ; draw minor ticks inward
>> res at tmYRMajorOutwardLengthF = 0.0 ; draw tickmarks inward
>> res at tmYRMinorOutwardLengthF = 0.0 ; draw minor ticks inward
>> ;res at tmXBMode = "Explicit" ;res at tmXBValues = ispan(0,120,10)
>> plot1 = gsn_csm_contour(wks,a,res) ; Create filled contours plot2 =
>> gsn_csm_contour(wks,b,res) ; Create filled contours;---Draw text and
>> markers at data locations txres = True mkres
>> = True txres at txFontHeightF = 0.01 txres at txJust = "TopCenter" ;
>> text will be drawn under the marker mkres at gsMarkerIndex = 16 ; filled
>> circle do j=0,11 do i=0,11
>> gsn_polymarker(wks,plot1,x(i),y(j),mkres) gsn_text(wks,plot1,"
>> ~C~"+a(j,i),x(i),y(j),txres)
>> gsn_polymarker(wks,plot2,x(i),y(j),mkres) gsn_text(wks,plot2,"
>> ~C~"+b(j,i),x(i),y(j),txres) end do end do;
>> frame(wks);************************************************; create
>> panel;************************************************resP =
>> True;resP at gsnPanelYWhiteSpacePercent =
>> 0.0gsn_panel(wks,(/plot1,plot2/),(/1,2/),resP) ; now draw as
>> one plotend*
>>
>>
>> Cheers,
>>
>> Tabish
>> Tabish U Ansari
>> PhD student, Lancaster Environment Center
>> Lancaster Univeristy
>> Bailrigg, Lancaster,
>> LA1 4YW, United Kingdom
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
>
> --
> Adam Phillips
> Associate Scientist, Climate and Global Dynamics Laboratory, NCAR
> www.cgd.ucar.edu/staff/asphilli/ 303-497-1726
>
> <http://www.cgd.ucar.edu/staff/asphilli>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190426/ac9d7c46/attachment.html>
More information about the ncl-talk
mailing list