[ncl-talk] draw a dot-line in a xy_plot and pots with different color on the plot according to the data value

Rick Brownrigg brownrig at ucar.edu
Fri Dec 30 09:17:56 MST 2016


Hi,

If I understand correctly, I see where you select data based upon levels to
be plotted in a specific color, with this line:

   ii = ind(levels(i).le.data(1,:).and.data(1,:).lt.levels(i+1))

But I don't see where you use the indices from "ii".  You have this line to
plot the markers:

   dot_fill_trn(i) = gsn_add_polymarker(wks,plot,data(0,:),data(1,:),mkres)

perhaps that should be:

   dot_fill_trn(i) = gsn_add_polymarker(wks,plot,
data(0,ii),data(1,ii),mkres)

??  This would explain why all the markers are the same color -- all the
data gets plotted each time through the loop and over-plotting what was
previously there, with the last used color prevailing.

I hope this helps...
Rick


On Fri, Dec 30, 2016 at 2:38 AM, grace <313695096 at qq.com> wrote:

> 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 found the example newcolor_4.
> <https://mail.qq.com/Scripts/newcolor_4.ncl>ncl which attach  pots with
> different size and color on the map according to the data value.
>
>  I have write a scirpt according to the example,but the dots have  same
> color.
> 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,:),data(1,:),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/20161230/893cac94/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2EE842E4 at B414B908.182B6658.jpg
Type: image/jpeg
Size: 159805 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161230/893cac94/attachment.jpg 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 76E0A045 at B414B908.182B6658.jpg
Type: image/jpeg
Size: 37332 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161230/893cac94/attachment-0001.jpg 


More information about the ncl-talk mailing list