Special Topics: Label Bars
There are many resources that modify label bars. This page will demonstrate only those we think will be commonly used. You can peruse the list of label bar resources for other options.
lb_1.ncl: Demonstrates a default
color bar. The default position is horizontal.
For the gsn_csm graphical interfaces, setting cnFillOn = True, automatically creates a color bar.
lbLabelBarOn = False, Will turn off the label bar.
lb_2.ncl: Vertical label bar and
explicit labels.
lbOrientation = "vertical", Moves the label bar to the right side vertical.
You can specify your own labels by setting lbLabelStrings equal to an array of strings. Here we chose other numbers, but the string could have any value.
lb_3.ncl: Large angled labels plus
adding a title.
lbLabelAngleF, Controls the angle of the labels while lbLabelFontHeightF, Controls the size of the labels.
A title can be added to the label bar by setting lbTitleOn equal to True, and providing a string using lbTitleString. The default position of the title is on top of the label bar. Example 4 demonstrates how to move the label bar title. The size of the label bar title can be changed with lbTitleFontHeightF.
In this example, we needed to move the entire label bar down b/c the oversized labels ran into the plot. pmLabelBarOrthogonalPosF adjust the label bar position perpendicular to the main plot axis. Note that this is a pm or plot manager resource.
lb_4.ncl: Title on the side, labels
in the center.
lbTitlePosition = "Right", Moves the title from its default top position to the right. Other options include bottom and left. If the title position is top or bottom, the default orientation of the title string is across. It is down if the title position is left or right. Here we override this default by changing the title orientation to across using lbTitleDirection.
The default position of the labels for the gsn_csm interfaces is lbLabelPosition = "ExternalEdges". We have changed this to the center using lbLabelAlignment = "BoxCenters".
The default label position is bottom, but this can be changed using lbLabelPosition.
The labels were made bolder by changing the font using lbLabelFont.
lb_5.ncl: How to create a label bar
from scratch.
As we indicated in the first example, the gsn_csm graphical interfaces automatically create a label bar if color is turned on. If you use the generic graphical interfaces then you may need to create a label bar from scratch.
To turn on and modify a label bar, you must first set lbAutoManage = False, and pmLabelBarDisplayMode = "Always".
The default orientation of the label bar in NCL is Vertical, and the default side is Right. We change these with lbOrientation and pmLabelBarSide respectively.
The default label bar width and height is shorter and taller than our aesthetic preference. Additionally, the default label font height is huge, and a box is draw around the label bar. We have modified these features using pmLabelBarWidthF, pmLabelBarHeightF, lbLabelFontHeightF, and lbPerimOn.
The number of labels on the label bar can be adjusted by setting lbLabelStride to some integer value. You can also use lbLabelAutoStride which automatically determines if there is a label overlap and adjusts the stride accordingly.
lb_6.ncl: Reverses the colormap.
The three resources (available since NCL version 4.2.0.a020) needed to
reverse a colormap are: gsnSpreadColors=
True
gsnSpreadColorStart= -1, starts
the colormap at the last color. gsnSpreadColorEnd = 2, Begins the colormap at the
beginning of the colormap.
lb_7.ncl: Changes the format
of the label bar labels so that they are all the same. The default
is not pretty when there is a different number of decimal places.
sprintf is the function we can use to reformat the labels. Unfortunately, this has to be done after the plot is drawn because there is no way to do it a priori.
lb_8.ncl: Automatically choose best
label bar stride.
lbLabelAutoStride will automatically determine the best stride for a label bar if it senses an overlap.
lb_9.ncl: Demonstrates how to create your
own label bar outside of a plot template call.
gsn_labelbar_ndc is the function that will draw your own label bar. You can use any of the resources demonstrated on this page to adjust the style of the label bar.
Note that gsnSpreadColors does not work on this label bar. See script for discussion and solution.
lb_10.ncl: Demonstrates how to add end
labels to a label bar.
The old method (before V5.0.0) was to set cnLabelBarEndLabelsOn to True. This has been deprecated, and you should now set cnLabelBarEndStyle to "IncludeMinMaxLabels". This will turn on labels at the ends of a label bar, using the min and max values of your data.
lb_11.ncl: Demonstrates how to attach
a labelbar to a plot.
gsn_create_labelbar is similar to gsn_labelbar_ndc except it returns an id that allows you to attach the labelbar to the plot using gsn_add_annotation.
The second frame shows how if you resize the plot, the labelbar automatically gets resized. Note that these two functions are only available in version 4.2.0.a034
lb_12.ncl: Demonstrates various ways
to control the end boxes of a labelbar.
A new contour resource called cnLabelBarEndStyle was added in V5.0.0. You can set this resource to one of three values to control how the end labelbar boxes are handled:
- "IncludeOuterBoxes" (frame 1, the default) - the first and last labels, representing the minimum and maximum contour levels, are aligned with the interior boundaries of the outer boxes.
- "IncludeMinMaxLabels" (frame 2) - the outer edges of the labelbar boxes are labeled with the min/max of the data.
- "ExcludeOuterBoxes" (frame 3) - the two outermost boxes are removed.