[ncl-talk] emphasize every parts of a line with different colors according to its y value.

Guido Cioni guidocioni at gmail.com
Fri Dec 30 12:21:01 MST 2016


I was going to reply with a similar recipe :) 

Basically, when drawing the line you have to split every segment and assign a color based on the average value of the y in that segment. 
This is just an hint, you will have to complete the code.

Assuming you have x,y which are your data values:

levels=fspan(min(y), max(y), 20)  ; define the levels for the colors, you can change this but it will always depend on the number of segments

cmap = read_colormap_file("amwg_blueyellowred") ; define the colormap that you want to use

do i=0,dimsizes(y)-1  ; loop over the segments 
   res at xyLineColors=GetFillColor(levels,cmap,avg((/y(i),y(i+1)/)))
   gsn_polyline(wks,plot,(/x(i),x(i+1)/),(/y(i),y(i+1)/),lres) 
end do

Guido Cioni
http://guidocioni.altervista <http://guidocioni.altervista/>.org

> On 30 Dec 2016, at 17:35, Rick Brownrigg <brownrig at ucar.edu> wrote:
> 
> Hi,
> 
> I don't know of any way of doing this other than to draw the line piecewise.  What about something like:
> 
> datadims = dimsizes(data)  ; assuming your data is 2xN
> numlinesegs = datadims(1) - 1
> linesegs = new((/ numlinesegs/), graphic)
> do i=1,numlinesegs
>   color = ....appropriate logic to determine the color here...
>   res at gsLineColor = color
>   linesegs(i) = gsn_add_polyline(wks, plot, data(0, i-1:i), data(1, i-1:i), res)
> end do
> 
> This is not particularly efficient, and there may be better ways of doing this, but that should work.
> 
> HTH...
> Rick
> 
> 
> On Fri, Dec 30, 2016 at 12:48 AM, grace <313695096 at qq.com <mailto:313695096 at qq.com>> wrote:
> Hi:
>   All,I am trying to  draw a line  that emphasize every parts of it with different colors.
> I have found the example xy_12.ncl which highlight the wanted part by split the data.
> But I want to draw a line which have different colors according to its y numberical value,just like the plot below.
> <0356412F at 5DA70B25.65116658.png>
> If I split the data ,that would be a huge work.
> Have anybody drawed plot like this ?Any information will be appreciated.
>  
>  
> 
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
> 
> 
> _______________________________________________
> 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/41caf4b2/attachment.html 


More information about the ncl-talk mailing list