Re: Text overlapping the map viewport using gsn_add_text

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu Jan 09 2014 - 10:10:48 MST

Hi Phillippe,

You don't need to draw the plot and advance the frame first in order for this to work. I only did this for illustrative purposes.

Go ahead and set:

> res@gsnDraw = False
> res@gsnFrame = False

before you create the plot. This means the plot will still be created, and hence you can retrieve the text information.

--Mary

On Jan 7, 2014, at 5:50 PM, Philippe Papin <ppapin@albany.edu> wrote:

> Hi Mary,
>
> Excellent! Thank you for taking the time to write up a new script to illustrate how string removal around the map border can be implemented. I've adapted a similar script into my code and now it removes the unnecessary text that runs outside of the map border.
>
> I do have one minor nagging issue, however. It seems that you have to at least draw and frame the plot once before extracting the useful NDC spacing of all the text viewports so you can later do the string removal. Is this true? The end result is that I end up with two images, the first one with the old text hanging along the border and the second image that removes this text. Right now I'm just removing the original image that's created, but if there is a way to be able to do the text removal without having to create an unnecessary extra image I'd be interested!
>
> Thanks,
> -Philippe
>
>
> On Mon, Jan 6, 2014 at 1:17 PM, Mary Haley <haley@ucar.edu> wrote:
> Hi Phillippe,
>
> There doesn’t appear to be a way to clip text that falls outside the plot. I tried this simple script:
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>
> begin
> wks = gsn_open_wks("x11","map")
>
> res = True
> res@mpCenterLonF = -60
> res@gsnDraw = False
> res@gsnFrame = False
> plot = gsn_csm_map(wks,res)
>
> txres = True
> txres@txFontHeightF = 0.04
> txres@txJust = "CenterLeft"
> id = gsn_add_text(wks,plot,"hello",-240,0,txres)
>
> draw(plot)
> frame(wks)
> end
>
> and the only thing I could do was set txJust to “CenterLeft”, as you see above.
>
> I’ve created a new example that shows how to remove text strings that fall outside a plot’s borders. It’s a bit complex, because you first need to add the strings, and then retrieve their locations to see if they are outside the borders. The NhlRemoveAnnotation procedure is then used to remove the offending text strings.
>
> This example was based on “text_10.ncl” on our examples page.
>
> See “text_17.ncl” at:
>
> http://www.ncl.ucar.edu/Applications/text.shtml
>
> —Mary
>
> On Jan 5, 2014, at 9:30 PM, Philippe Papin <ppapin@albany.edu> wrote:
>
>> Hi NCL Talk,
>>
>> I have what is hopefully a simple problem. I've been making a simple black and white map with tropical cyclone tracks overlaid (with a text box located to the upper right of the track highlighting the system's name). Occasionally this textbox appears on the edge of the map domain and overlaps with the map viewport, creating an image that looks like this:
>>
>> http://www.atmos.albany.edu/student/ppapin/lb13_img/html/gridsat_grid/ibtracs_trans_atl_73.png
>>
>> Instead of the remainder of the text showing up outside of the map, I'd like it to be buried underneath without any visible information outside of the map domain. In its current configuration it makes the horizontal size of the image larger than it needs to be (note the differences between the text outside of the map vs. text only inside of the map).
>>
>> Is this possibly a viewport issue? I am using gsn_add_text to write text to the map domain. I would be happy to provide additional code if necessary to figure out what is going on.
>>
>> Thanks,
>> Philippe
>>
>> --
>> -------------------------------------
>> Philippe P. Papin
>> Dept. of Atmospheric and Environmental Sciences
>> University at Albany, SUNY
>> 1400 Washington Ave, Albany, NY 12222
>> http://www.atmos.albany.edu/student/ppapin/
>> _______________________________________________
>> 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
>
>
>
>
> --
> -------------------------------------
> Philippe P. Papin
> Dept. of Atmospheric and Environmental Sciences
> University at Albany, SUNY
> 1400 Washington Ave, Albany, NY 12222
> http://www.atmos.albany.edu/student/ppapin/
> _______________________________________________
> 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
Received on Thu Jan 9 10:11:01 2014

This archive was generated by hypermail 2.1.8 : Sun Jan 19 2014 - 21:56:35 MST