Unexpected behavior from lgItemOrder

From: Travis O'Brien <taobrien_at_nyahnyahspammersnyahnyah>
Date: Thu Nov 29 2012 - 15:55:28 MST

Dear NCL Developers,

I have encountered some unexpected behavior in the usage of lgItemOrder
with gsn_legend_ndc() to control the order of legend items. From the
documentation, I expect that when I explicitly set lgItemOrder, all aspects
of the legend items (including color, dash pattern, and legend string) will
be re-ordered accordingly. However, it seems that the legend string is not
reordered along with the rest of the legend elements, which leads to a
mismatched legend. I have pasted a simple script below my signature to
demonstrate this issue. The png generated by this script on my machine can
be accessed here:
http://dl.dropbox.com/u/43145817/BugReports/lgItemOrder_bug_test.png

The script draws three legends: the first (leftmost) with no reordering,
the second (middle) with reordering, and the third (rightmost) with a
workaround to produce the expected behavior. The first legend demonstrates
the expected correspondence between line color/style and legend string.
 The second panel demonstrates that the line color/styles are re-ordered,
but the legend strings are not, which leads to an inconsistent legend
(notice that the color named in the legend string no longer corresponds to
the line color). The third panel shows what I expected that lgItemOrder
would do in the second panel; I achieved this by passing a manually
re-ordered version of the legend strings.

If this is not actually a bug, then perhaps a note might be added to the
lgItemOrder documentation to clarify the behavior of this resource.

This test was run with ncl 6.1.0 on a 64-bit Ubuntu 12.04 system (output
from uname -a: 3.2.0-33-generic #52-Ubuntu SMP Thu Oct 18 16:29:15 UTC 2012
x86_64 x86_64 x86_64 GNU/Linux).

Please let me know if I can provide any further clarification.

Thank you,
-Travis-

-- 
Travis A. O'Brien
Climate Science Postdoctoral Fellow
Lawrence Berkeley National Lab
http://esd.lbl.gov/about/staff/travisobrien/
__________________________________________________________
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
begin
  ;Set up a simple test with four items.  The line labels correspond
  ; to the color of the line, with the number corresponding to the expected
  ; placement when lgItemOrder is used.
  nitems=4
  colors = (/"red","green","cyan","blue"/)
  labels = (/"red - 3","green - 1","cyan - 4","blue - 2"/)
  dashes = (/0,1,2,3/)
  res = True
  res@lgLineColors = colors       ;Set legend colors
  res@lgDashIndexes = dashes      ;Set legend dash patterns
  res@lgLineThicknessF = 5.0      ;Draw thick lines
  ;Give the legend a moderate size so that we can fit two legends
  res@vpWidthF = 0.3
  res@vpHeightF = 0.3
  ;Open the worksheet
  wks = gsn_open_wks("png","lgItemOrder_bug_test")
  ;Draw the first legened, with the items ordered as explicitly set above.
  ;In this test, the numbers shouldn't match the ordering
  gsn_legend_ndc(wks,nitems,labels,0.0,1.0,res)
  ;Now set lgItemOrder so that the labels should go in numerical order
  res@lgItemOrder = (/1,3,0,2/)
  ;Draw the second legend, with the items reodered.
  ;In this test, the numbers should match the ordering and the color labels
  ;should match the line colors (they don't in my test)
  gsn_legend_ndc(wks,nitems,labels,0.35,1.0,res)
  ;Draw the third legend, with a workaround: provide the labels in the order
  ;explicitly given by res@lgItemOrder
  gsn_legend_ndc(wks,nitems,labels(res@lgItemOrder),0.7,1.0,res)
  frame(wks)
end

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Nov 29 15:55:58 2012

This archive was generated by hypermail 2.1.8 : Fri Dec 21 2012 - 10:43:23 MST