[ncl-talk] BoxCenters in pyNGL

Clinton Rowe crowe1 at unl.edu
Wed Aug 22 07:20:53 MDT 2018


Thanks, Mary.  The workaround you provided works like a charm and my maps no longer have the extraneous default label.  Not only did the last box get labeled as I wanted, but it labeled ever box, as I wanted.  The labelbar on my map (not on contour2.py) is horizontal, so I guess the extra long label for the last box made it go to labeling every other box to avoid overlapping labels.

I’ll look into installing pyNGL under Python 3 and testing that out.

Thanks, again, for all your superb support!
Clint

========================================================
Clinton M. Rowe
Professor and Graduate Chair         phone:(402)472-1946
Earth & Atmospheric Sciences           fax:(402)472-4917
University of Nebraska- Lincoln           crowe1 at unl.edu<mailto:crowe1 at unl.edu>

From: Mary Haley <haley at ucar.edu>
Sent: Tuesday, August 21, 2018 5:23 PM
To: Clinton Rowe <crowe1 at unl.edu>
Cc: ncl-talk at ucar.edu
Subject: Re: [ncl-talk] BoxCenters in pyNGL

Hi Clint,

I've been looking into this and it appears to be a bug.

Normally, you are supposed to be able to set your own labels using lbLabeStrings, but it appears that the contour object has to be in a certain "state" (i.e. it has to have been created already) in order for the labels to take effect.

A work-around is to use set_values, which allows you to apply resource changes to an object that has already been created.

I've attached a modified contour2.py that creates two PNGs. The first PNG is the plot with the bug. The second one is with the correct labels set using "set_values".

BTW, this is not a PyNGL bug, but an internal NCL graphics bug. The reason why you don't see this bug when you use NCL's gsn_csm_contour function is because that function constructs the labelbar from scratch.

And a second BTW, PyNGL is now officially available under Python 3. I need to update some documentation on this, but if you use conda, it should give you the Python 3 version by default:

conda create --name pyn_env --channel conda-forge pyngl

I made a slight change to "contour2.py" so it would work under Python 3, which was this line:

nrlist.lbLabelStrings = list(range(-30,110,10))

Under Python 2, it looked like this:

nrlist.lbLabelStrings = range(-30,110,10)

U
nder Python 3, the above line will give you the error:

  value for keyword lbLabelStrings is invalid.

Traceback (most recent call last):
  File "contour2.py", line 41, in <module>
    Ngl.set_values(contour,nrlist)
  File "/Users/haley/miniconda3/envs/pyn_env_py3/lib/python3.6/site-packages/ngl/__init__.py", line 5622, in set_values
    values = NhlSetValues(_int_id(obj),rlist)

SystemError: <built-in function NhlSetValues> returned NULL without setting an error

Let me know if you continue to have problems with PyNGL. We are trying to put more attention on this package to clean it up and feedback is very useful!

Thanks,

--Mary




On Tue, Aug 21, 2018 at 7:00 AM, Clinton Rowe <crowe1 at unl.edu<mailto:crowe1 at unl.edu>> wrote:
Hi Mary,

I upgraded to the latest pyNGL release and add lbLabelStrings to my code, and I still get the last box labeled with a generic label (Label_13), even though I have 14 labels defined.  On my first try, I accidentally used 30 as my step size when generating the labels and that made no difference in how the labelbar was labeled.

What am I missing here?

Clint

========================================================
Clinton M. Rowe
Professor and Graduate Chair         phone:(402)472-1946
Earth & Atmospheric Sciences           fax:(402)472-4917
University of Nebraska- Lincoln           crowe1 at unl.edu<mailto:crowe1 at unl.edu>

From: Mary Haley <haley at ucar.edu<mailto:haley at ucar.edu>>
Sent: Thursday, August 16, 2018 7:28 PM
To: Clinton Rowe <crowe1 at unl.edu<mailto:crowe1 at unl.edu>>
Cc: ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
Subject: Re: [ncl-talk] BoxCenters in pyNGL

Hi Clint,

Sorry for taking so long to get back to this. I'm slowing climbing my way back to normalcy after a few weeks of constant meetings.

I'm wondering if this example has been fixed in the latest PyNGL, because it worked fine for me, although one label is missing because once you go to box centers, you have to provide an additional label. (You can add the extra label with lbLabelStrings.)

I installed PyNGL and PyNIO with:

conda create --name pyn_env --channel conda-forge pynio pyngl

and then ran your attached script, with the resultant attached image.

Do you know what version of PyNGL you're running? You can print "Ngl.__version__
" for this information.

--Mary

On Fri, Aug 3, 2018 at 10:43 AM, Clinton Rowe <crowe1 at unl.edu<mailto:crowe1 at unl.edu>> wrote:
Mary, Rick, et al.,

I transitioned a routine from NCL to pyNGL and the BoxCenters label resource is not working.  Labels are only drawn at alternate interior lines on the labelbar, rather than the box centers as desired.  As an example, I added one line to contour2.py to request labels at the center of the boxes.  I’ve attached the modified example and output png.

Thanks,
Clint

========================================================
Clinton M. Rowe
Professor and Graduate Chair         phone:(402)472-1946
Earth & Atmospheric Sciences           fax:(402)472-4917
University of Nebraska- Lincoln           crowe1 at unl.edu<mailto:crowe1 at unl.edu>

_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk<https://urldefense.proofpoint.com/v2/url?u=http-3A__mailman.ucar.edu_mailman_listinfo_ncl-2Dtalk&d=DwMFaQ&c=Cu5g146wZdoqVuKpTNsYHeFX_rg6kWhlkLF8Eft-wwo&r=ubRAum_abJ_VeyWwkZyVzQ&m=8cUMz0iNSykheFbeusuXgwm6yRiLJGxOl84WZqwmJNc&s=bnEJJeofaPnySgZWsqUV6F4_5KhWCcFLPajWl_fIn34&e=>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180822/72569998/attachment.html>


More information about the ncl-talk mailing list