Re: scatter plot w/ colors

From: Alessandra Giannini <alesall_at_nyahnyahspammersnyahnyah>
Date: Fri, 16 Jan 2009 16:06:05 -0500

Adam,

I am glad you could sort out the workings of the GetFillColor. I would
have never made it out alive...

Now it works! With one more change:

gsn_polymarker(wks,plota,x,y,pres)
in the loop actually needs to be changed to:
gsn_polymarker(wks,plota,x(j),y(j),pres)

otherwise, at every iteration, all the dots get colored by the same
color, and you end up with all the dots of the same final color.

Thank you very much. Now I can go home and enjoy the weekend ;-)

best, alessandra

On Jan 16, 2009, at 2:25 PM, Adam Phillips wrote:

> Hi Alessandra,
>
> I see what you mean. Looking at the coding of GetFillColor, I didn't
> realize that it wants a complete colormap to be input, with the
> foreground and background colors included. That adds a bit of code
> to what I sent you last night, and I tweaked a couple other lines
> after testing out what I sent you yesterday.
>
> Here's what I have for my test script:
>
> pres = True
> z = random_uniform(-50,50,(/100/)) ; random timeseries
>
> arr = nice_mnmxintvl(min(z),max(z),21,False)
> ;--------round added to get rid of Argument type mismatch error
> sorted_z = fspan(arr(0),arr(1),round(((arr(1)-arr(0))/arr(2))+1,3))
>
> wks = gsn_open_wks("x11","test")
> gsn_define_colormap(wks,"BlWhRe")
> cmap = gsn_retrieve_colormap(wks)
> ncolors = dimsizes(cmap(:,0)) ; number of colors
>
> c_ind = round(fspan(2,ncolors-1,dimsizes(sorted_z)+1),3) ; round to
> int
> ncmap = new((/dimsizes(c_ind)+2,3/),typeof(cmap)) ; add black + white
> ncmap(:1,:) = cmap(:1,:)
> ncmap(2:,:) = cmap(c_ind,:)
> delete(cmap)
>
> do j=0,dimsizes(z)-1
> pres_at_gsMarkerColor=GetFillColor(sorted_z,ncmap,z(j))
> print(pres_at_gsMarkerColor)
> ; gsn_polymarker(wks,plota,x,y,pres)
> end do
>
> Notice I'm not plotting anything, I'll leave that to you. Let me
> know if this version doesn't work as advertised..
> Adam
>
> Alessandra Giannini wrote:
>> Adam,
>> thanks for your reply, and example. I can follow what you are
>> doing, but I still get this complaint:
>> "Not enough colors in colormap for number of contour levels"
>> The line is repeated many times - too many for me to try and count
>> them... ;-)
>> I checked the dimensions of the vectors, and even when I reduce the
>> z, sorted_z vectors to be smaller in dimension than the original
>> color map it gives me the same error.
>> The problem is in the line where the "GetFillColor" function is
>> applied - if I comment that out it runs, but obviously does not
>> produce the desired output.
>> Do you have any insights?
>> Thanks very much!
>> best, alessandra
>> On Jan 15, 2009, at 6:09 PM, Adam Phillips wrote:
>>> Hi Alessandra,
>>>
>>> If you wanted to automatically come up with your contour (for lack
>>> of a better word) levels, you can use nice_mnmxintvl first:
>>> http://www.ncl.ucar.edu/Document/Functions/Built-in/nice_mnmxintvl.shtml
>>>
>>> arr = nice_mnmxintvl(min(z),max(z),21,False)
>>> sorted_z = fspan(arr(0),arr(1),((arr(1)-arr(0))/arr(2))+1)
>>>
>>> Now let's say you wanted to use the BlWhRe colormap:
>>> http://www.ncl.ucar.edu/Document/Graphics/ColorTables/BlWhRe.shtml
>>>
>>> wks_define_colormap(wks,"BlWhRe")
>>> cmap = gsn_retrieve_colormap(wks)
>>> dimz = dimsizes(cmap)
>>> ncolors = dimz(0) ; number of colors
>>> c_ind = round(fspan(2,ncolors-1,dimsizes(sorted_z)+1),3) ; round
>>> to int
>>> do j=0,dimsizes(z)-1
>>> pres_at_gsMarkerColor=GetFillColor(sorted_z,cmap(c_ind,:),z(j))
>>> gsn_polymarker(wks,plota,x,y,pres)
>>> end do
>>>
>>> (untested) I think that will do it.. If that doesn't do what you
>>> want, let us know..
>>> Adam
>>>
>>> Alessandra Giannini wrote:
>>>> Hi everyone,
>>>> I am trying to figure out how to plot a scatterplot of THREE
>>>> variables in the following way:
>>>> the first variable runs along the x-axis, the second along the y-
>>>> axis and the third adds variation in color to the points.
>>>> To give you a prototypical example, here is a plot of average
>>>> temperature/precipitation colored by elevation in stations around
>>>> the central Mediterranean, computed in the IRI Data Library:
>>>> <http://iridl.ldeo.columbia.edu/expert/SOURCES/.NOAA/.NCDC/.GCPS/.MONTHLY/.STATION/lon/%280%29%2820%29masknotrange/SELECT/lat/%2835%29%2845%29masknotrange/SELECT/mean/temp%5BT%5Daverage/1/index/.prcp%5BT%5Daverage/3/index/.elev/fig://XOVY/1/def/scattercolor/:fig/
>>>> >
>>>> In NCL I tried this way a while back - start with the scatterplot
>>>> of 2 variables:
>>>> plot = gsn_csm_xy(wks,x,y,res)
>>>> and then add color:
>>>> pres = True
>>>> pres_at_gsMarkerIndex = (/ 16 /)
>>>> pres_at_gsMarkerSizeF = (/ 0.01 /)
>>>> do j=0,dimsizes(z)-1
>>>> pres_at_gsMarkerColor=GetFillColor(sorted_z,cmap,z(j))
>>>> gsn_polymarker(wks,plota,x,y,pres) end do
>>>> where cmap is defined from an array or RGB values, stored in an
>>>> external file:
>>>> cmap = RGBtoCmap("csimple.txt")
>>>> that typically looks like this:
>>>> 255 255 255
>>>> 0 0 0
>>>> 0 0 128
>>>> 0 0 205
>>>> 30 144 255
>>>> 0 191 255
>>>> 127 255 212
>>>> 255 255 255
>>>> 255 255 0
>>>> 255 215 0
>>>> ...
>>>> My problem is in defining a color scale automatically, in the
>>>> sense that I would like to be able to just pick out a color map
>>>> regardless of the number of points in the scatter - one of the
>>>> classic color scales defined in ncl would do, like BlueRed.
>>>> Can I do that? And if so, how?
>>>> Your help is much appreciated.
>>>> thanks, alessandra
>>>> --
>>>> Alessandra Giannini
>>>> IRI for Climate and Society - The Earth Institute at Columbia
>>>> University
>>>> P.O. Box 1000, Palisades NY 10964-8000
>>>> phone/fax: +1 845 680-4473/4864 - email: alesall_at_iri.columbia.edu
>>>> <mailto:alesall_at_iri.columbia.edu>
>>>> ------------------------------------------------------------------------
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>> --
>>> --------------------------------------------------------------
>>> Adam Phillips asphilli_at_ucar.edu
>>> National Center for Atmospheric Research tel: (303) 497-1726
>>> ESSL/CGD/CAS fax: (303) 497-1333
>>> P.O. Box 3000 Boulder, CO 80307-3000 http://www.cgd.ucar.edu/cas/asphilli
>
> --
> --------------------------------------------------------------
> Adam Phillips asphilli_at_ucar.edu
> National Center for Atmospheric Research tel: (303) 497-1726
> ESSL/CGD/CAS fax: (303) 497-1333
> P.O. Box 3000
> Boulder, CO 80307-3000 http://www.cgd.ucar.edu/cas/asphilli

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Jan 16 2009 - 14:06:05 MST

This archive was generated by hypermail 2.2.0 : Wed Jan 21 2009 - 13:09:21 MST