[ncl-talk] reply: draw a dot-line in a xy_plot and pots with differentcolor on the plot according to the data value
Hoffman Cheung
hoffmancheung at gmail.com
Tue Jan 3 02:27:06 MST 2017
Hi Grace,
If you want to know where the error occurs, please refer to the line
specified in the error message, which is* line 84* in your case.
Also, according to the error message, the error occurred when reading data
but not plotting the marker:
fatal:*Subscript out of range, error in **subscript #1*
fatal:*An error occurred reading data*
fatal:["Execute.c":8567]:Execute: Error occurred at or near* line 84* in
file xypot_aqi.ncl
When I go through your script, I think the problem is related to the line
extracting the indices for a range of levels:
do i=0,nlevels-2
; print(i)
* ii = ind(levels(i).le.data(1,:).and.data(1,:).lt.levels(i+1)**)*
mkres at gsMarkerIndex = 16 ; Filled dots
mkres at gsMarkerSizeF = 5
mkres at gsMarkerColor = colors(i)
print(colors(i))
;---Make markers partly transparent (1.0 is fully opaque)
mkres at gsMarkerOpacityF = 0.9
dot_fill_trn(i) = gsn_add_polymarker(wks,plot,data(0,*ii*),data(1,*ii*
),mkres)
delete(ii)
end do
The following is the definition of the variables for extracting the indices:
data(1,:)=(/10,25,56,90,230,450,490/)
levels = ispan(0,500,50)
As there is *no data *for some range of levels (between 100 and 200,
between 300 and 400), *ii *would be assigned a missing value as returned by
the *ind *function in these circumstances. Then, in the line plotting the
marker, the script cannot extract *data *(as *ii *contains missing value)
and results in an error message.
To solve your problem, you can add a conditional statement to check whether
*ii *is missing when plotting the marker, i.e.:
* if (.not. any(ismissing(ii))) then*
dot_fill_trn(i) = gsn_add_polymarker(wks,plot,data(0,ii),data(1,ii
),mkres)
*end if*
Cheers, Hoffman
2017-01-03 2:03 GMT+01:00 grace <313695096 at qq.com>:
> Hi:
> All,I am trying to draw a dot-line in a xy_plot that emphasize
> different parts of it with different colors according to its values.
> I have write a scirpt according to the example,but the dots have same
> color.According to Rick's advise,I've changed the "dot_fill_trn(i) =
> gsn_add_polymarker(wks,plot,data(0,:),data(1,:),mkres) "
> to "dot_fill_trn(i) = gsn_add_polymarker(wks,plot,da
> ta(0,ii),data(1,ii),mkres)",but error occurred:
>
> fatal:Subscript out of range, error in subscript #1
> fatal:An error occurred reading data
> fatal:["Execute.c":8567]:Execute: Error occurred at or near line 84 in
> file xypot_aqi.ncl
>
> I don't know why and can't find where the problem is.
>
> This is my script:
> 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
> ;---Read in file as array of strings so we can parse each line.
> ; filename= "/public/home/huanglei/bias_T_5km.txt"
> ; lines := asciiread(filename,-1,"float")
> ; nlines = dimsizes(lines)-1 ; First line is a header
>
> data=new((/2,7/),float)
> ; data(1,:)=lines(:,1) ;;get the aqi_data
> data(1,:)=(/10,25,56,90,230,450,490/)
> ;;;;;;;;;;;;;;;;;;;make X axis;;;;;;;;;;;;;;;;;;;;;;
> ;d1=new(1272,float)
> ;d1(0)=1
> ;do s=1,1271
> ; d1(s)=d1(s-1)+1
> ;end do
> data(0,:) = (/1,2,3,4,5,6,7/)
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ; We generate plots, but what kind do we prefer?;;;;make a fake plot to
> attach the pots ,line is white;;;
> type = "pdf"
> wks = gsn_open_wks(type,"xypot_aqi")
>
> res1=True
> res1 at gsnFrame = False
> res1 at gsnDraw = False
> res1 at xyLineThicknesses = 0.1 ; make 2nd lines thicker
> res1 at xyLineColors = "white" ; change line color
> res1 at pmLegendDisplayMode = "always" ; turn on legend
> res1 at pmLegendSide = "Top" ; Change location of
> res1 at pmLegendParallelPosF = .89 ; move units right
> res1 at pmLegendOrthogonalPosF = -1.17 ; more neg = down
> res1 at lgPerimOn = False ; No legend perimeter.
> res1 at trXMinF =1
> res1 at trXMaxF =7
> res1 at tmXBMode ="Explicit"
> res1 at tmXBValues =(/1,2,3,4,5,6,7/)
> res1 at tmXBLabels = (/"8/1"," 8/11"," 8/21"," 9/1","9/11", \
> " 9/21","9/20"/)
> res1 at vpHeightF = 0.35
> res1 at vpWidthF = 0.75
> ;res1 at tiYAxisString = "mm" ; add an axis title
> res1 at gsnLeftString ="AQI of Xian"
> res1 at pmLegendWidthF = 0.10 ; Change width and
> res1 at pmLegendHeightF = 0.10 ; height of legend.
> res1 at lgLabelFontHeightF = 0.02 ; change font
> height
> plot= gsn_csm_xy(wks,d1,data(1,:),res1)
> ;;;;;;attach the different color pots according to the data value;;;
> ;---Generate some levels to group the data values by.
> levels = ispan(0,500,50)
> nlevels = dimsizes(levels)
> ;;;;;;;;;;;---For each range, we want a different color.
> colors = (/"yellow","green","orange","red","violet","violet","
> violetred4","violetred4","violetred4","violetred4"/)
> ;;;;Arrays for attaching markers;;;
> dot_fill_trn = new(nlevels-1,graphic)
> ; For each range, gather the data that falls in this range
> ; and draw the set of markers at those x/y locations.
> ;
> mkres = True
> do i=0,nlevels-2
> ; print(i)
> ii = ind(levels(i).le.data(1,:).and.data(1,:).lt.levels(i+1))
>
> mkres at gsMarkerIndex = 16 ; Filled dots
> mkres at gsMarkerSizeF = 5
> mkres at gsMarkerColor = colors(i)
> print(colors(i))
> ;---Make markers partly transparent (1.0 is fully opaque)
> mkres at gsMarkerOpacityF = 0.9
> dot_fill_trn(i) = gsn_add_polymarker(wks,plot,
> data(0,ii),data(1,ii),mkres)
> delete(ii)
> end do
> ;---Drawing the map plots will draw all the attached markers too.
> draw(plot)
> frame(wks)
> end
> Can you slove this problem?Any information will be appreciated.
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170103/c43b3005/attachment.html
More information about the ncl-talk
mailing list