; ------------------------------------------------- --------------------- ; box_6.ncl ; ; Concepts illustrated: ; - Drawing box plots using statistics calculated with stat_dispersion ; - Using text function codes to generate accented characters ; ------------------------------------------------- --------------------- ; This script was contributed by Guilherme Martins of the ; National Institute for Space Research. ; ------------------------------------------------- --------------------- ; These files are loaded by default in NCL and newer V6.2.0 ; Load "$ NCARG_ROOT / lib / ncarg / nclscripts / csm / gsn_code.ncl" ; Load "$ NCARG_ROOT / lib / ncarg / nclscripts / csm / gsn_csm.ncl" ; Load "$ NCARG_ROOT / lib / ncarg / nclscripts / csm / contributed.ncl" ;load "$ NCARG_ROOT / lib / ncarg / nclscripts / csm / shea_util.ncl" begin ; The pr.djf.cx2.txt file has four columns in the following order with precipitation values ; (Mm / day) to the northeast of the Amazon for the months of DJF (1979-2005). ; Col1 Col2 Col3 Col4 ; GPCP ACCESS1-0 BCC-CSM1.1 CANESM2 atxt="pr.djf.cx2.txt"; file name in txt format. nLines=numAsciiRow(atxt); lines of the file number. ncolumns=numAsciiCol(atxt); File column number. f=asciiread(atxt,(/nLines,ncolumns/),"float"); Opening the text file. this file ; It has 78 rows and 4 columns. opt=True; Enables customization of statistics. opt@PrintStat=True; Screen shows the result of statistic stat_dispersion function. ; The line below prints on the screen the result of statistic for each variable. sr1=stat_dispersion(f(:,0),opt); f (:, 0) = all rows of the first column (GPCP). sr2=stat_dispersion(f(:,1),opt); f (:, 1) = all rows of the second column (ACCESS1-0). sr3=stat_dispersion(f(:,2),opt); f (:, 2) = all rows of the third column (BCC-CSM1.1). sr4=stat_dispersion(f(:,3),opt); f (:, 3) = all rows in the fourth column (CAESM2). sr5=stat_dispersion(f(:,4),opt); f (:, 4) = all rows in the fourth column (CAESM2). sr6=stat_dispersion(f(:,5),opt); f (:, 5) = all rows in the fourth column (CAESM2). sr7=stat_dispersion(f(:,6),opt); f (:, 6) = all rows in the fourth column (CAESM2). sr8=stat_dispersion(f(:,7),opt); f (:, 7) = all rows in the fourth column (CAESM2). sr9=stat_dispersion(f(:,8),opt); f (:, 8) = all rows in the fourth column (CAESM2). sr10=stat_dispersion(f(:,9),opt); f (:,9) = all rows in the fourth column (CAESM2). sr = sr1 print(sr(2)+".."+sr(6)+".."+sr(8)+".."+sr(10)+".."+sr(14)) ; The values (2), (7), (8), (11) and (14) below correspond to: the minimum value, ; first quartile, median, third quartile and the maximum value of the series, respectively. yval=new((/10,5/),"float",-999.) yval(0,0)=sr1(2); Size of the lower stem. yval(0,1)=sr1(6); First quartile. yval(0,2)=sr1(8); Median. yval(0,3)=sr1(10); Third quartile. yval(0,4)=sr1(14); Size of upper stem. yval(1,0)=sr2(2); Size of the lower stem. yval(1,1)=sr2(6); First quartile. yval(1,2)=sr2(8); Median. yval(1,3)=sr2(10); Third quartile. yval(1,4)=sr2(14); Size of upper stem. yval(2,0)=sr3(2); Size of the lower stem. yval(2,1)=sr3(6); First quartile. yval(2,2)=sr3(8); Median. yval(2,3)=sr3(10); Third quartile. yval(2,4)=sr3(14); Size of upper stem. yval(3,0)=sr4(2); Size of the lower stem. yval(3,1)=sr4(7); First quartile. yval(3,2)=sr4(8); Median. yval(3,3)=sr4(11); Third quartile. yval(3,4)=sr4(14); Size of upper stem. yval(4,0)=sr5(2); Size of the lower stem. yval(4,1)=sr5(7); First quartile. yval(4,2)=sr5(8); Median. yval(4,3)=sr5(11); Third quartile. yval(4,4)=sr5(14); Size of upper stem. yval(5,0)=sr6(2); Size of the lower stem. yval(5,1)=sr6(7); First quartile. yval(5,2)=sr6(8); Median. yval(5,3)=sr6(11); Third quartile. yval(5,4)=sr6(14); Size of upper stem. yval(6,0)=sr7(2); Size of the lower stem. yval(6,1)=sr7(7); First quartile. yval(6,2)=sr7(8); Median. yval(6,3)=sr7(11); Third quartile. yval(6,4)=sr7(14); Size of upper stem. yval(7,0)=sr8(2); Size of the lower stem. yval(7,1)=sr8(7); First quartile. yval(7,2)=sr8(8); Median. yval(7,3)=sr8(11); Third quartile. yval(7,4)=sr8(14); Size of upper stem. yval(8,0)=sr9(2); Size of the lower stem. yval(8,1)=sr9(7); First quartile. yval(8,2)=sr9(8); Median. yval(8,3)=sr9(11); Third quartile. yval(8,4)=sr9(14); Size of upper stem. yval(9,0)=sr10(2); Size of the lower stem. yval(9,1)=sr10(7); First quartile. yval(9,2)=sr10(8); Median. yval(9,3)=sr10(11); Third quartile. yval(9,4)=sr10(14); Size of upper stem. x=ispan(1,ncolumns,1); Values for the x-axis. wks=gsn_open_wks("PNG","box") res=True res@tmXBLabelAngleF = 45; Gradient text. res@tmXBLabels=(/"SR1","SR2","SR3","SR4","SR5","SR6","SR7","SR8","SR9","SR10"/); X - axis labels. res@tiMainString="SR1 to SR10"; Title of the figure. res@vpHeightF = 0.7 res@vpWidthF = 0.7 opti=True opti@boxWidth = .8 ; Width of box (x opti@boxColors=(/"black","red","black","red","black","red","black","red","black","red"/) llres = True llres@gsLineThicknessF = 2.5 plot=boxplot(wks,x,yval,opti,res,llres); Generation boxplot. draw(wks) frame(wks) end