NCL Home> Application examples> Plot techniques || Data files for some examples

Example pages containing: tidbits | resources | functions/procedures

Bar Charts

Bar charts in this context are simply XY plots that are drawn with bars for each X,Y point. There is a separate page for creating histograms.

Multi-colored bar charts: example 6

Pattern-filled bar charts: example 7

bar_1.ncl: Bar chart examples. The first frame just sets gsnXYBarChart to True, which causes each Y value to be represented by a bar pointing upward. The base of each bar is the minimum Y value or the value of trYMinF, if set.

The second frame additionally sets gsnXYBarChartOutlineOnly to True, which causes each Y value to be represented by a horizontal bar, creating an outline plot. There are no individual bars drawn here.

The third frame sets gsnYRefLine to 0, causing all the positive Y values to be drawn as bars pointing upward, and all negative Y values to be drawn as bars pointing downward.

bar_2.ncl: Demonstrates coloring values above and below a reference line with a particular color.

gsnAboveYRefLineColor = "red", and gsnBelowYRefLineColor = "blue", are the two resources required to shade the bars above and below the reference line.

bar_3.ncl: Demonstrates changing the size of the bars.

By default, the thickness of each bar is delta-x. You can make the bars smaller than this by setting gsnXYBarChartBarWidth to a smaller number. In this instance, delta-x is 0.66 and we have changed the width to 0.1. Note that at this point it becomes hard to see the bar colors, because the bars are pretty thin.

bar_4.ncl: Demonstrates turning off bar outline around each bar. This is useful when you have a lot of data points because the outline is drawn after the color fill, and a black line and can obscure it.

xyLineColors = (/"red","blue"/), changes the outline color for the above and below color filled areas respectively.

bar_5.ncl: Multiple bar chart on one page.
bar_6.ncl: Demonstrates how to make individual bars different colors within a bar chart that has a reference line. The colors can be chosen separately for the above and below bars (first plot), or sequentially regardless of orientation (second plot).

gsnAboveYRefLineBarColors controls the colors of the bars above the reference line. This is an array. The colors will repeat. gsnBelowYRefLineBarColors controls the colors below the reference line.

gsnXYBarChartColors2 will assign a sequence of colors regardless of bar orientation.

bar_7.ncl: A bar chart w/o a reference line, and individual colors. The second frame adds a labelbar.

gsnXYBarChartColors controls the colors of the bars.

bar_8.ncl: Demonstrates how to make individual bars different colors and patterns within a bar chart that has a reference line. Colors are distributed separately for bars above and below the reference line (first plot), or regardless of orientation of the bars (second plot).

gsnAboveYRefLineBarPatterns controls the patterns of the bars above the reference line. This is an array. The patterns will repeat. gsnBelowYRefLineBarPatterns controls the patterns below the reference line.

gsnXYBarChartPatterns2 will apply the patterns regardless of the orientation of the bars.

There are several patterns to choose from.

bar_9.ncl: This script creates a single bar chart showing 4 different timeseries with four different colors. The labelbar is created by using gsn_labelbar_ndc.
polyg_10.ncl: This example shows how to draw various polylines and polygons on a several generic tickmark backgrounds to create a series of bar charts. The gsn_add_polyline and gsn_add_polygon functions are used to create the polylines and polygons and gsn_panel is used to panel all the plots on one frame.
bar_11.ncl: This script shows how to panel multiple bar charts and add a custom legend (using labelbars).

This example is similar to example 9 above, except it uses the overlay procedure to overlay the individual bar plots. Finally, it uses gsn_panel to panel the four sets of plots.