Re: Why doesn't my text show up in my plot?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri Feb 28 2014 - 10:48:00 MST

Craig,

If you set gsnFrame and gsnDraw to False, then the plot object will be created, but nothing will get drawn. It shouldn't matter if your output is going to PS, PNG, X11, PDF, or NCGM.

Whenever you set these two resources to False, then in order to have the plot drawn correct, you need to call:

  draw(plot)
  frame(wks)

where "plot" is whatever you used for the variable on the left side of the "=":

   plot = gsn_csm_contour_map(…)

I think what's happening in your case is that if you set these two resources to False, and don't call "draw" and "frame", then for the "ps" case, you will still get a "xxxx.ps" file, but it will be blank. For the "png" case, you will get no file at all.

Look at your PS file to see if it actually has any graphics in it. I won't be surprised if it doesn't.

Are you actually calling "draw" and "frame" somewhere in your code?

See the attached script for an example. Try commenting out the "draw" and "frame" calls and see what happens.

--Mary

On Feb 28, 2014, at 9:57 AM, Craig Tierney - NOAA Affiliate <craig.tierney@noaa.gov> wrote:

> Mary,
>
> In developing an example I found the problem, but it lead to another issue. I had not set res@gsnFrame and res@gsnDraw to false like I had done in other similar commands, so I was unable to plot any additional objects after the call to gsn_csm_contour_map. So that is pretty obvious why it isn't working.
>
> However, this lead to another issue I had never asked about. I would rather be generating png files directly, and not creating ps files and converting them after the fact. This code was able to write directly to png files with:
>
> wks=gsn_open_wks("png",ofn);
>
> However, when I changed gsnFrame and gsnDraw to false, I could no longer create png files. I can create ps files by just changing the command above to use "ps".
>
> Should I be able to create png files directly with gsnFrame and gsnDraw set to false?
>
> If you need to see my example, please send me instructions on where to upload it.
>
> Thanks,
> Craig
>
>
>
> On Wed, Feb 26, 2014 at 3:06 PM, Mary Haley <haley@ucar.edu> wrote:
>
> On Feb 26, 2014, at 1:54 PM, Craig Tierney - NOAA Affiliate <craig.tierney@noaa.gov> wrote:
>
> > Mary,
> >
> > I will try and come up with an example. The gsn_add_text isn't working either. Now, I could be using it wrong (most likely).
> >
> > My question is, should gsn_add_text be able to plot text outside of the boundary of the plot map?
>
> No, you can only use gsn_add_text for text inside the plot's boundaries, although you can do a kludgy thing of moving the text by adding extra spaces or carriage returns to the text string.
>
> --Mary
>
> >
> > Thanks,
> > Craig
> >
> >
> > On Wed, Feb 26, 2014 at 1:26 PM, Craig Tierney - NOAA Affiliate <craig.tierney@noaa.gov> wrote:
> > On Wed, Feb 26, 2014 at 12:45 PM, Mary Haley <haley@ucar.edu> wrote:
> > Craig,
> >
> > Can you trim this down to a short but complete script that illustrates the problem? I can't tell from looking at the code snippet what might be going on.
> >
> >
> > I will see what I can do. The plotting script is really 1000+ lines of NCL that allow me plot any dataset, from any resolution, of any meteorological field, and just do the right thing. This script is plotting a data on a icosahederal grid.
> >
> > There could be a maximization issue, or maybe one plot element is covering up another, etc.
> >
> > Note: generally I recommend against using gsn_text_ndc (or any of the gsn_xxx_ndc procedures) if you can use gsn_add_xxx instead.
> >
> >
> > I was not a fan of working in NDC space, but it did help me simplify my code because when the scripts change domain (eg. global to conus), then I would have to rescale the coordinates. In NDC space and an assumption of where the plot ends up, I can safely tuck away the text in the corner of the plot.
> >
> > The difference, of course, is that with gsn_xxx_ndc you need to use NDC coordinates (coordinates from 0 to 1), whereas with the gsn_add_xxx functions you need to use the plot's coordinate space. Also, with gsn_xxx_ndc, the primitive gets drawn right in that moment and it is *not* attached to anything. The gsn_add_xxx function will attach the primitive to the plot, but not draw it. So, you have to draw the plot in order to see the primitive. But, the benefit is if you resize the plot, then the primitive will be resized automatically.
> >
> >
> > I will try the gsn_add_text and see if that resolves the order issue.
> >
> > Craig
> > --Mary
> >
> > On Feb 26, 2014, at 11:59 AM, Craig Tierney - NOAA Affiliate <craig.tierney@noaa.gov> wrote:
> >
> > > I am using ncl 6.1.2. When I try to call gsn_text_ndc before the call to gsn_csm_contour_map, the text displays.
> > >
> > > ----------------------------
> > > ; Create a control string for the plot
> > > cstr="Min/Max control: "+min(d1)+"/"+max(d1)+" "+"Min/Max Diff: "+min(data)+"/"+max(data)
> > > print(cstr)
> > >
> > > ; Attach all necessary labels
> > > txresb = True
> > > txresb@txFontHeightF = 0.010
> > > gsn_text_ndc(wks,cstr, 0.5, 0.1, txresb)
> > >
> > > ; plot the map
> > > map = gsn_csm_contour_map(wks,data,res)
> > >
> > > draw(map)
> > > -----------------------------
> > >
> > > When I reverse it, the text does not display.
> > >
> > > ----------------------------
> > > ; Create a control string for the plot
> > > cstr="Min/Max control: "+min(d1)+"/"+max(d1)+" "+"Min/Max Diff: "+min(data)+"/"+max(data)
> > > print(cstr)
> > >
> > > ; plot the map
> > > map = gsn_csm_contour_map(wks,data,res)
> > >
> > > ; Attach all necessary labels
> > > txresb = True
> > > txresb@txFontHeightF = 0.010
> > > gsn_text_ndc(wks,cstr, 0.5, 0.1, txresb)
> > >
> > > draw(map)
> > > -----------------------------
> > >
> > > Why is this and is there a way to enable additional debugging so that I could see what NCL is doing when I run into future problems like this?
> > >
> > > Thanks,
> > > Craig
> > > _______________________________________________
> > > 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 Fri Feb 28 10:48:10 2014

This archive was generated by hypermail 2.1.8 : Mon Mar 03 2014 - 14:26:18 MST