[ncl-talk] text res

Mary Haley haley at ucar.edu
Sat Oct 17 14:23:35 MDT 2015


Geeta,

Any time you create a graphical object, like a plot, a text string, a
polyline, etc, a "graphical object" gets created. This graphical object has
a variable type of "graphic".

The reason I had to create an array of graphic objects is because for every
graphic object you create, you need to make sure it has a unique name. If
you don't, then only the last graphic object you create with this name will
exist, and you would end up with only one text string.

See the attached example script and image.  This shows what happens if you
don't use a unique id.  I used a unique id for the green markers, but not
for the blue markers, so you only see one of the blue markers in the script.

[Thanks to Karin Meier-Fleischer whose script I based this example on.]

I've updated our "Polygons, Polymarkers, Polylines, and Text" examples page
to include more information about the need for unique ids:

http://www.ncl.ucar.edu/Applications/polyg.shtmll

--Mary

On Fri, Oct 16, 2015 at 11:31 AM, Geeta Geeta <geetag54 at yahoo.com> wrote:

> thanks again.
> It worked.
> Just one clarification.
> So "text" is a varaible created by "new" and it's type is "graphic".
> Kindly can you tell me about the "graphic" type of variable. prob the
> details of this type are not covered in the web page.
>
> thanks again.
>
>
>
>
>
>
> Geeta.
>
>
>
> On Friday, 16 October 2015 9:53 PM, Mary Haley <haley at ucar.edu> wrote:
>
>
> Geeta,
>
> Your "if" statement is wrong.  The condition "if any(rf.le.4.1)" is always
> going to resolve as True, because you are checking if *any* one of the rf
> values is <= 4.1. The "else" part of the statement never gets executed.
>
> If you want to set a different font color for each value, then you will
> need a do loop, because unfortunately we don't have a "txFontColors" type
> of resource that allows you to set an array of colors.
>
> Here's what your loop would look like:
>
>   nrf    = dimsizes(rf)
>   colors = where(rf.le.4.1,"Blue","Red")
>   text   = new(nrf,graphic)
>   do n=0,nrf-1
>     txres at txFontColor = colors(n)
>     text(n) =
> gsn_add_text(wks,plot,sprintf("%9.4g",rf(n)),lon(n),lat(n),txres)
>   end do
>   draw(plot)
>   frame(wks)
>
>
> On Thu, Oct 15, 2015 at 11:49 AM, Geeta Geeta <geetag54 at yahoo.com> wrote:
>
> Yes I meant "clumsy " as the values close to the dots.
> Yes all your suggestions are working very well.
> Thanks a lot for that.
>
> I have another question. I was wondering if I can give different colours
> to the values. I mean if rainfall in in range of 0.1-2.4, then I write the
> actual value by Yellow color
> if 2.5  -10.0 say then I write the actual value by Green color
>
> Instead of all uniform colour like Blue I have chosen
>
> For this I tried with if statement before the Text Res like this.
>
>   txres                    = True
>   txres at txFontHeightF      = 0.012
>   txres at txFont             = "helvetica-bold"
> ;
>     if any(rf.le.4.1) then
>   txres at txFontColor        = "Blue"
> ;  txres at txFontQuality      = "High"
> ;  txres at txJut             = "TopRight "
> else
> if any(rf.gt.4.1) then
> txres at txFontColor        = "Red"
> end if
> end if
>
>   text  = gsn_add_text(wks,plot,"  "+sprintf("%9.4g",rf),lon,lat,txres)
>
> But It is plotted in Blue only.
> my input file looks like this.
> lat         lon        hgt      rf
> 12.57   77.38   919.6  5.6
> 12.3    78.18   882.2  67.
> 13.06   77.24   900    0.1
> 13.26   77.24   900    4.1
>
> If I dont use any function then I get error.
>
> Geeta.
>
>
>
> On Wednesday, 14 October 2015 12:34 AM, Mary Haley <haley at ucar.edu> wrote:
>
>
> Geeta,
>
> I'm not sure what you mean by "messy".
>
> You are setting txPosXF and txPosYF, but these resources are meaningless,
> because the "gsn_add_text" function has the X and Y positions as part of
> its argument list, in your case, the "lon" and "lat" arguments:
>   text  = gsn_add_text(wks,plot,sprintf("%9.4g",rf),lon,lat,txres)
> So, you should be trying to change your lon and lat values, and not
> txPosXF and txPosYF.
> If by "messy" you mean that the text string is touching the markers in a
> couple of places, then there are several things you can do.
> One is to simply add some extra spaces before the text strings. You can do
> this by changing the format in the "sprintf" call to have more fields:
>   text  = gsn_add_text(wks,plot,sprintf("%11.4g",rf),lon,lat,txres)
> or by adding a space:
>   text  = gsn_add_text(wks,plot,"  " + sprintf("%9.4g",rf),lon,lat,txres)
> You can also add a small delta value to the "lon" position:
>   text  = gsn_add_text(wks,plot,sprintf("%9.4g",rf),lon+0.1,lat,txres)
> --Mary
>
>
>
>
>
> On Mon, Oct 12, 2015 at 11:14 AM, Geeta Geeta <geetag54 at yahoo.com> wrote:
>
> Hi.
> I am plotting station rainfall and my data looks like
> 13.57   77.38   919.6  5.6
> 12.3    78.18   882.2  67.
> 13.06   77.24   900    0.1
> 13.06   77.24   900    0.1
> ~
> The Rf is in the 4th Col and it gets plotted. But when I try to change the
> position of the text, I am unable to do it.
> My script is attached and the Figure.
>
> essentially,
>
>   txres at txPosXF            = 0.775
>   txres at txPosYF            = -5.05
> ;  txres at txAngleF           = 40.00
>
> Since I am unable to change the above two, my plot looks a little messy.
>
> can someone suggest???
>
> Geeta.
>
> _______________________________________________
> 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/20151017/dd6d5af8/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: poly_example.png
Type: image/png
Size: 48976 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151017/dd6d5af8/attachment.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: poly_example.ncl
Type: application/octet-stream
Size: 1797 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151017/dd6d5af8/attachment.obj 


More information about the ncl-talk mailing list