BarChart := proc(L0::{list,array,Array}) option `Maple Advisor Database 1.01 for Maple 6`, `Copyright (c) 2000 by Robert B. Israel. All rights reserved`; local L, _labels, _colours, _stacked, _percent, _horizontal, opts, i, opt, bars, T; _labels := NULL; _colours := NULL; _stacked, _horizontal, _percent:= false, false, false; opts := NULL; if type(L0,list) then L:= L0 else L:= convert(L0,listlist) fi; for i from 2 to nargs do opt := args[i]; if type(opt, name = list) then if op(1, opt) = 'barlabels' then _labels := op(2, opt); if nops(_labels) <> nops(L) then ERROR(nops(L), " items but ", nops(_labels), " labels") end if elif member(op(1, opt), ['colour','color']) then _colours := op(2, opt); else opts := opts, opt end if elif opt = 'stacked' then _stacked:=true elif opt = 'percent' then _percent:= true elif opt = 'horizontal' then _horizontal:= true else opts := opts, opt end if end do; if _percent then if type(L,list(list)) then for i from 1 to nops(L) do T:= 100.0/convert(L[i],`+`); L[i]:= T*L[i]; od; else T:= 100.0/convert(L,`+`); L:= T*L; fi fi; if _colours = NULL then _colours := [red] elif not type(_colours,list) then _colours := [_colours] fi; if not type(L,list(list)) then if _stacked then L:= [L] else L:= map(t -> [t],L) fi fi; if _labels = NULL then _labels := [seq(i, i = 1 .. nops(L))] end if; _labels := map(proc(x) if type(x, {name, string}) then x elif type(x, float) then sprintf("%f", x) else sprintf("%a", x) end if end proc, _labels); if _horizontal then _labels:= ytickmarks = [seq(-i-.4 = _labels[i],i=1..nops(_labels))] else _labels:= xtickmarks = [seq(i + .4 = _labels[i], i = 1 .. nops(_labels))] fi; bars:= seq(`BarChart/bars`(L[i],i,_colours,_stacked,_horizontal), i=1..nops(L)); plots[display]({bars}, opts, axes = FRAME, _labels); end proc; `BarChart/bars`:= proc(L, i, colours, stacked, horiz) option `Maple Advisor Database 1.01 for Maple 6`, `Copyright (c) 2000 by Robert B. Israel. All rights reserved`; local nbars, ncol, b,T,j,res; nbars:= nops(L); ncol:= nops(colours); res:= NULL; if nbars > 1 then if stacked then T:= 0; for j from 1 to nbars do if horiz then res:= res, plottools[rectangle]([T,-i],[T+L[j],-i-.8], colour=colours[(j-1) mod ncol + 1]); else res:= res, plottools[rectangle]([i,T],[i+.8,T+L[j]], colour=colours[(j-1) mod ncol + 1]); fi; T:= T+L[j] od else b:= 4/(6*nbars-1); if horiz then res:= seq(plottools[rectangle]( [0,-i-(j-1)*1.2*b], [L[j],-i-(1.2*j-.2)*b], colour = colours[(j-1) mod ncol + 1]), j = 1 .. nbars); else res:= seq(plottools[rectangle]( [i+(j-1)*1.2*b,0], [i+(1.2*j-.2)*b,L[j]], colour = colours[(j-1) mod ncol + 1]), j = 1 .. nbars); fi fi elif horiz then res:= plottools[rectangle]([0,-i],[L[1],-i-.8], colour = colours[(i-1) mod ncol + 1]); else res:= plottools[rectangle]([i,0],[i+.8,L[1]], colour = colours[(i-1) mod ncol + 1]); fi; res end;