[ncl-talk] Boxplot line is invisible in the plot

Atul Saini atulsainimail at gmail.com
Fri May 24 22:49:07 MDT 2019


Hi,
        I would like to know the missing part in my code which is leading
to the missing lines in the boxplot in NCL. Please help the code and the
data file is attached here and while running the code take care of changing
the path of the data file "pr.djf.cx2.txt" in the code.

Regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190525/85ebce68/attachment.html>
-------------- next part --------------
141	141	141	141	145	148	148	159	155	155
147	147	148	148	150	150	150	154	154	155
151	151	153	153	158	168	168	168	169	169
163	167	167	167	169	175	175	171	177	175
146	146	156	159	159	160	164	160	164	162
-------------- next part --------------
; ------------------------------------------------- ---------------------
; 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="/media/atul/Seagate_Atul/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 at 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).


; 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(7); First quartile.
yval(0,2)=sr1(8); Median.
yval(0,3)=sr1(11); 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(7); First quartile.
yval(1,2)=sr2(8); Median.
yval(1,3)=sr2(11); 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(7); First quartile.
yval(2,2)=sr3(8); Median.
yval(2,3)=sr3(11); 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 at tmXBLabelAngleF = 45; Gradient text.
res at tmXBLabels=(/"SR1","SR2","SR3","SR4","SR5","SR6","SR7","SR8","SR9","SR10"/); X - axis labels.
res at tiMainString="SR1 to SR10"; Title of the figure.
res at vpHeightF = 0.7
res at vpWidthF = 0.7

opti=True
opti at boxWidth = .8 ; Width of box (x
opti at boxColors=(/"black","red","black","red","black","red","black","red","black","red"/) 

llres                   = True			
llres at gsLineThicknessF  = 2.5 	
	
plot=boxplot(wks,x,yval,opti,res,llres); Generation boxplot.

draw(wks)
frame(wks)

end



More information about the ncl-talk mailing list