[ncl-talk] Percentage outputs for pie charts

Brian Squitieri brianjs at iastate.edu
Mon Feb 29 15:57:50 MST 2016


Good Afternoon,

I have been attempting to plot percentages within a pie chart, but I
receive the following output and associated error for my NCL script:

(0)     Percent of peak wind times at 0000 UTC: 0%
(0)     Percent of peak wind times at 0300 UTC: 6.45161%
(0)     Percent of peak wind times at 0600 UTC: 51.6129%
(0)     Percent of peak wind times at 0900 UTC: 35.4839%
(0)     Percent of peak wind times at 1200 UTC: 6.45161%
(0)     Percent Total: 100%
fatal:fspan: number of elements parameter is less-than-or-equal-to one,
can't continue
fatal:["Execute.c":8575]:Execute: Error occurred at or near line 4026 in
file $NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl

fatal:["Execute.c":8575]:Execute: Error occurred at or near line 44 in file
pie_chart_example.ncl

Reviewing past NCL help requests in 2010 and 2015 have shown that an
adjustment was necessary for the pie_chart function; specifically
npts = round( pcPie(n), 3)
changes to
npts = max( (/round( pcPie(n), 3), 1/) )

I run NCL version 6.3.0 and this adjustment is already made in the base
code, and all variables in my script are converted to floats. Output shows
that the sum of all percentages equates to one hundred, so I am unsure what
is wrong here. I had attempted to round both with and without truncation,
but nothing was helpful. Any assistance would be greatly appreciated. Below
is the code and attached is the .txt file which contains the data set used.


;Load vital libraries and begin program
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Retrieve data from .txt file
        ruc  =
asciiread("/tera0/brianjs/observations/ruc_analysis/LLJ_stats/LLJ_stats_all.txt",-1,"string")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;First, retrieve time data as a string
        ruc_time  = str_get_field(ruc,4,",")

;Convert data into floats
        ruc_times  = stringtofloat(ruc_time)
        dimall = new(1,float)
        dimall = dimsizes(ruc_times)

;Calculate time percentages statistics
        count = new(5,float)
        count = (/1,3,6,9,12/)          ;Corresponds to 0000 UTC, 0300 UTC,
0600 UTC, 0900 UTC, and 1200 UTC, respectively

        time_percents = new(5,float)
do i = 0,4
        time_percents(i) = (num(ruc_times.eq.count(i))/dimall)*100
end do
print("Percent of peak wind times at 0000 UTC: "+time_percents(0)+"%")
print("Percent of peak wind times at 0300 UTC: "+time_percents(1)+"%")
print("Percent of peak wind times at 0600 UTC: "+time_percents(2)+"%")
print("Percent of peak wind times at 0900 UTC: "+time_percents(3)+"%")
print("Percent of peak wind times at 1200 UTC: "+time_percents(4)+"%")
print("Percent Total: "+sum(time_percents)+"%")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Pie chart resources
        wks = gsn_open_wks("x11","LLJ_time_stats")
        color = (/"red","dark green","blue","purple","sienna3"/)
        name = (/"0000 UTC","0300 UTC","0600 UTC","0900 UTC","1200 UTC"/)

        pres = True
        pres at gsnDraw  = False
        pres at gsnFrame = False

;Pie Chart
        pie = pie_chart(wks,time_percents,name,color,pres)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160229/17921cec/attachment.html 
-------------- next part --------------
5/24/2007,27.6,750,9,36.312115,-95.611572
5/25/2010,24.0,500,6,34.105503,-99.987854
5/27/2013,29.9,750,9,37.824032,-99.304871
5/28/2013,36.1,1000,6,37.824032,-95.474701
5/30/2007,22.8,500,9,37.126091,-94.927307
6/01/2007,25.1,500,6,35.963394,-99.304871
6/02/2010,32.4,500,6,37.475044,-99.168213
6/02/2011,33.8,500,6,39.685474,-101.761169
6/02/2014,24.9,500,6,35.150112,-98.894836
6/04/2013,27.1,750,6,38.173058,-97.253723
6/04/2014,32.9,750,6,38.405735,-97.800934
6/07/2010,25.9,500,6,37.824032,-102.714203
6/07/2014,26.1,750,6,31.905407,-102.578125
6/11/2010,31.9,500,9,36.428371,-101.079590
6/12/2014,27.6,500,9,32.715008,-99.714691
6/15/2012,23.2,1250,3,36.079624,-98.621460
6/15/2014,34.9,1250,6,38.871124,-97.527344
6/16/2012,22.9,500,9,37.358723,-102.986206
6/16/2013,21.4,750,9,38.289394,-95.337860
6/17/2013,18.5,750,6,34.453560,-98.211243
6/18/2010,31.5,750,6,37.707695,-100.670349
6/19/2010,26.5,500,6,36.893486,-101.215942
6/20/2010,28.7,1250,9,39.336479,-100.124390
6/21/2010,27.1,750,6,39.103809,-99.851288
6/28/2014,32.9,750,6,37.126091,-99.031555
7/06/2011,18.9,500,9,32.946545,-100.260925
8/09/2010,23.5,750,3,40.267029,-94.516754
8/17/2009,25.7,500,9,34.221512,-102.986206
8/19/2009,29.6,750,12,38.522091,-98.758148
8/20/2011,20.3,500,9,34.917877,-99.168213
8/30/2011,20.9,500,12,32.599270,-100.943207


More information about the ncl-talk mailing list