[pyngl-talk] labelbar strings with contour
Mary Haley
haley at ucar.edu
Tue May 15 15:33:51 MDT 2018
Hi Matt,
I'm so sorry I didn't see this question sooner.
I have to admit that this one stumped me. It is much easier to do this
using the gsn_csm_contour_map function in NCL, because that function is
reconstructing the labelbar from scratch, and it explicitly allows you to
change this resource.
PyNGL, on the other hand, is using the default labelbar that's provided
when you create a contour plot, and apparently this default doesn't like
you trying to change the label strings.
I was able to get this to work by creating the plot, and then setting the
label strings after the fact using set_values. Please see the attached
example script. Hopefully you can run it as is, but here are the lines that
are important:
# After plot is created, then we can change the labels (?!)
rlist = Ngl.Resources()
rlist.lbLabelStrings = ["one","","three","four"]
Ngl.set_values(map.contour,rlist)
Ngl.draw(map)
Ngl.frame(wks)
Meanwhile, I've filed a ticket on this (PYNGL-114), because it shouldn't be
this hard.
--Mary
On Wed, May 9, 2018 at 2:51 PM, Fearon, Dr. Matthew, Contractor, Code 7533
via pyngl-talk <pyngl-talk at ucar.edu> wrote:
> Dear PyNGL Users:
>
>
>
> Trying to contour with ExplicitLevels and alter labelbar strings. Here’s
> my resource settings below with the image attached (see label bar). I am
> not getting the labelbar strings I was hoping for (ie, levels). I have
> tried having the following variable “levels” be a list or numpy array.
> Results remain the same. Any thoughts would be much appreciated.
>
>
>
> Thank you,
>
> Matt
>
>
>
>
>
> sres.cnFillMode = "RasterFill"
>
> sres.cnLevelSelectionMode = "ExplicitLevels"
>
> levels = np.asarray([2,4,7.5,14,27,53,
> 103,200,386,745,1439,2779,5365,10359,20000])
>
> sres.cnLevels = levels
>
>
>
> sres.lbAutoManage = False
>
> sres.lbLabelStride = 2
>
> sres.pmLabelBarWidthF = 0.018
>
> sres.lbLabelFontHeightF = 0.009
>
> sres.pmLabelBarOrthogonalPosF = 0.002
>
> sres.lbLabelStrings = levels
>
> _______________________________________________
> pyngl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/pyngl-talk/attachments/20180515/f78cec7c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: change_labels.py
Type: text/x-python-script
Size: 1043 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/pyngl-talk/attachments/20180515/f78cec7c/attachment.bin>
More information about the pyngl-talk
mailing list