topbar_plot
Graphics
Parameters
values
in
required
Keywords
baselines
colors
barnames
title
xtitle
ytitle
baserange
barwidth
barspace
baroffset
outline
overplot
background
rotate
Examples
By using the overplotting capability, it is relatively easy to create
stacked bar charts, or different groups of bars on the same graph.
For example, if ARRAY is a two-dimensional array of 5 columns and 8
rows, it is natural to make a plot with 5 bars, each of which is a
"stacked" composite of 8 sections. First, create a 2D COLORS array,
equal in size to ARRAY, that has identical color index values across
each row to ensure that the same item is represented by the same color
in all bars.
With ARRAYS and COLORS defined, the following code fragment
illustrates the creation of stacked bars (note that the number of rows
and columns is arbitrary):
!Y.RANGE = [0,ymax] ; Scale range to accommodate the total bar lengths.
BASE = INTARR(NROWS)
FOR I = 0, NROWS-1 DO BEGIN
BAR_PLOT, ARRAY(*,I), COLORS=COLORS(*,I), BASELINES=BASE, $
BARWIDTH=0.75, BARSPACE=0.25, OVER=(I GT 0)
BASE = BASE + ARRAY(*,I)
ENDFOR
To plot each row of ARRAY as a clustered group of bars within the same
graph, use the BASERANGE keyword to restrict the available plotting
region for each set of bars. The sample code fragment below
illustrates this method:
FOR I = 0, NROWS-1 DO $
BAR_PLOT, ARRAY(*,I), COLORS=COLORVECT, BARWIDTH=0.8,BARSPACE=0.2, $
BAROFFSET=I*((1.0+BARSPACE)*NCOLS), OVER=(I GT 0), BASERANGE=0.19
where NCOLS is the number of columns in ARRAY, and COLORVECT is a
vector containing the color indices to be used for each group of
bars. (In this example, each group uses the same set of colors, but
this could easily be changed.)
Version history
History
August 1990, T.J. Armitage, RSI, initial programming. Replacement
for PLOTBAR and OPLOTBAR routines written by William Thompson.
September 1990, Steve Richards, RSI, changed defaults to improve the
appearance of the bar plots in the default mode. Included
spacing the bars slightly.
$Id: bar_plot.pro 142 2006-07-21 12:47:49Z navarro $