Note: Please see the BARPLOT function, which replicates the functionality of this routine and offers an interactive interface.

The BAR_PLOT procedure creates a bar graph. This routine is written in the IDL language. Its source code can be found in the file bar_plot.pro in the lib subdirectory of the IDL distribution.

Syntax


BAR_PLOT, Values [, BACKGROUND=color_index] [, BARNAMES=string_array] [, BAROFFSET=scalar] [, BARSPACE=scalar] [, BARWIDTH=value] [, BASELINES=vector] [, BASERANGE=scalar{0.0 to 1.0}] [, COLORS=vector] [, /OUTLINE] [, /OVERPLOT] [, /ROTATE] [, TITLE=string] [, XTITLE=string] [, YTITLE=string]

Arguments


Values

A vector containing the values to be represented by the bars. Each element in Values corresponds to a single bar in the output.

Keywords


BACKGROUND

A scalar that specifies the color index to be used for the background color. By default, the normal IDL background color is used.

BARNAMES

A string array, containing one string label per bar. If the bars are vertical, the labels are placed beneath them. If horizontal (rotated) bars are specified, the labels are placed to the left of the bars.

BAROFFSET

A scalar that specifies the offset to be applied to the first bar, in units of “nominal bar width”. This keyword allows, for example, different groups of bars to be overplotted on the same graph. If not specified, the default offset is equal to BARSPACE.

BARSPACE

A scalar that specifies, in units of “nominal bar width”, the spacing between bars. For example, if BARSPACE is 1.0, then all bars will have one bar-width of space between them. If not specified, the bars are spaced apart by 20% of the bar width.

BARWIDTH

A floating-point value that specifies the width of the bars in units of “nominal bar width”. The nominal bar width is computed so that all the bars (and the space between them, set by default to 20% of the width of the bars) will fill the available space (optionally controlled with the BASERANGE keyword).

BASELINES

A vector, the same size as Values, that contains the base value associated with each bar. If not specified, a base value of zero is used for all bars.

BASERANGE

A floating-point scalar in the range 0.0 to 1.0, that determines the fraction of the total available plotting area (in the direction perpendicular to the bars) to be used. If not specified, the full available area is used.

COLORS

A vector, the same size as Values, containing the color index to be used for each bar. If not specified, the colors are selected based on spacing the color indices as widely as possible within the range of available colors (specified by !D.N_COLORS).

OUTLINE

If set, this keyword specifies that an outline should be drawn around each bar.

OVERPLOT

If set, this keyword specifies that the bar plot should be overplotted on an existing graph.

ROTATE

If set, this keyword indicates that horizontal rather than vertical bars should be drawn. The bases of horizontal bars are on the left, “Y” axis and the bars extend to the right.

TITLE

A string containing the main title for the bar plot.

XTITLE

A string containing the title for the X axis.

YTITLE

A string containing the title for the Y axis.

Examples


By using the overplotting capability, it is relatively easy to create stacked bar charts, or different groups of bars on the same graph.

The example bar_plot_doc.pro creates a two-dimensional array of 5 columns and 8 rows, and creates a plot with 5 bars, each of which is a “stacked” composite of 8 sections. This example file is installed in the IDL installation’s /examples/doc/plot directory. To view the example code, enter .edit bar_plot_doc.pro at the IDL command line. To execute the code, enter bar_plot_doc at the IDL command line.

Version History


Pre 4.0

Introduced

See Also


PLOT Procedure, BARPLOT, PLOT