Re: txFontColor as an array?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Jun 18 2012 - 08:53:10 MDT

Hi Ozan,

Internally, when you create a text string, you can only create one "text object" at a time, and hence there's only the concept of a singular "txFontColor".

gsn_add_text allows you to input an array of text strings, and then internally it creates arrays of text objects, one for each string. So, unfortunately, there's
no meaning for "txFontColors".

However, it was fairly simple to create my own version of "gsn_add_text" string (in $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl") and add recognition of "txFontColors".

This version might slightly improve the slowness, as it sets the font color during the creation of the text object, rather than applying it afterwards (via a "setvalues" call).
I also just wanted to show how it's possible to modify functions in gsn_code.ncl yourself, if you need to add your own functionality.

I will add it to our list to have the text object enhanced so you can create an array of text strings. I think this should be possible.

--Mary

On Jun 15, 2012, at 9:12 AM, ozan mert gokturk wrote:

> Dear All,
>
> I am trying to attach lots of number strings to a plot by using gsn_add_text. I want to adjust the color of each string according to their value, i.e. warmer colors for greater numbers (please see attached image). The problem is, since the resource txFontColor can only be assigned a single value and not an array, I have to construct a do loop which changes the value of txFontColor each time. And this takes VERY long, as there are 363 strings to attach to the plot.
>
> Code snippet for the long loop:
>
> txres=True
> text = new(dimsizes(dolu),graphic);
> iSize = dimsizes(dolu) - 1
> do i=0, iSize
> deger=temp_dolu(i)
> sira=dolu(i)
> if (deger.lt.maxsic).and.(deger.gt.minsic) then
> txres@txFontColor = 2 + floattoint((deger-minsic)*incr)
> text(i) = gsn_add_text(wks,map,sprintf("%6.4g",round(deger,0)),x(sira),y(sira),txres) ; Add the number texts
> end if
> end do
>
>
> Instead, I tried:
>
>
> txres@txFontColor = 2 + floattoint((temp_dolu-minsic)*incr)
> text = gsn_add_text(wks,map,sprintf("%6.4g",round(temp_dolu,0)),x(dolu),y(dolu),txres)
>
>
> where temp_dolu is the temperature array that I try to put on the map. This gives no error, but txFontColor takes the first value of the array that is assigned, so all my numbers on the map are the same color.
>
> Can you kindly suggest any other (fast) ways of accomplishing this? You can maybe tell me where in the source code I can change the behavior of txFontColor, so that it takes on arrays as well?
>
> Thanks in advance,
>
> Ozan
> <temps.png>_______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

text_example.png
Received on Mon Jun 18 08:57:51 2012

This archive was generated by hypermail 2.1.8 : Mon Jun 25 2012 - 09:57:23 MDT