Function:
BarChart - produce a bar chart from data
Calling sequence:
BarChart(L, options);
Parameters:
L
- a list, list of lists, or one- or two-dimensional array or Array
options
- many of the usual two-dimensional plot options, plus
stacked
,
horizontal
,
percent
, and
barlabels = B
, where
B
is a list.
Description:
-
This procedure produces a bar chart. If its first argument
L
is a list or one-dimensional array or Array of numbers, this consists of evenly-spaced bars, one for each member of
L
, with length proportional to the number. If
L
is a list of lists or a two-dimensional array or Array of numbers, the bars for each list (or each row of the array or Array) are grouped together.
-
If the option
stacked
is used, a stacked bar chart is produced. Instead of the bars in each group being side-by-side, they are placed end-to-end.
-
By default the bars are vertical. If the option
horizontal
is used, the bars are horizontal.
-
If the option
percent
is used, the items in each group are shown as a fraction of the group total. If the items are not grouped, all items are shown as a fraction of the total of all items.
-
If the option
barlabels = B
is used, each group is labelled by one of the entries of the list
B
. If the items are not grouped, each item is labelled. An error results if there are too few labels for the items or groups. If there is no
barlabels
option, the groups or items are labelled 1, 2, 3, ... .
-
If the option
colour = L
is used, where
L
is a list, then each bar is coloured with a colour from the list
L
. If the items are grouped, the colours within each group are assigned according to the members of
L
. If there are more items than colours, the colours repeat. If there is no
colour
option, all bars are red. You may use the spelling
color
instead of
colour
.
-
As in any two-dimensional plot, the option
labels = [xlabel,ylabel]
, where
xlabel
and
ylabel
are strings, produces labels for the horizontal and vertical axes. Other useful plot options include
axesfont
,
labeldirections
,
labelfont
,
style
,
thickness
,
title
,
titlefont
,
xtickmarks
and
ytickmarks
.
-
This procedure is part of the Maple Advisor Database.
Examples:
A simple bar chart.
>
BarChart([3,1,4,1,5]);
The same data, but using horizontal bars, specified colours and labels.
>
BarChart([3,1,4,1,5],horizontal,colour=[red,yellow,green,blue,magenta],barlabels=["A","B","C","D","E"]);
Bar chart with groups, using the
percent
option. Note that the groups can be of different sizes. The
style=line
option causes the bars to be shown in outline only.
>
BarChart([[1,2,3,4],[4,5,6],[7,8]],percent,barlabels=[First,Second,Third],percent,colour=[red,green,blue],thickness=2,style=line);
The same data in a stacked bar chart.
>
BarChart([[1,2,3,4],[4,5,6],[7,8]],percent,barlabels=[First,Second,Third],percent,stacked,colour=[red,green,blue]);
>