Re: Bar Chart Options Question

*To*: mathgroup at smc.vnet.net*Subject*: [mg54614] Re: [mg54581] Bar Chart Options Question*From*: "Christoph Lhotka" <lhotka at astro.univie.ac.at>*Date*: Thu, 24 Feb 2005 03:21:16 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

On Wed, 23 Feb 2005 03:12:04 -0500 (EST) Namrata Khemka <namrata.khemka at gmail.com> wrote: > Hi Everyone, > I am trying to do the following with bar chart. > > t = {1,2,3,4,0,6,7,8,9,10,11,12,13} > BarChart[t] > > However, I would like 2 bars to be of a particular color. By this I > mean, for the bars with value 1 and 2, it could be red, for bars with > value 3 and 4 it could be green. and so on. > > One of the other things that I would like to do is, label the bars. I > would like to have 1 label for bars with value 1 and 2. Another label > for bars with values 3 and 4 and so on.. > > Any suggestions as to how this can be done? > > Thanks a lot in advance. > > Namrata Khemka > With the data In[..]:=data=Range[13]; Use Options Ticks and BarStyle to solve your formatting problem. If you define a list of color directives, like In[..]:=colortable={col1,col1,col2,col2,...}; where coli is RGBColor[...] or GrayLevel[.] or something like that, and define explicit tick marks of the form: In[..]:= helpvar=Table[{i, i}, {i, 1, 5}] // Flatten Out[..]:= {1, 1, 2, 2, 3, 3, 4, 4, 5, 5} In[..]:= tickstable={Table[{i, helpvar[[i]]}, {i, 1, 10}], Automatic}; In[..]:=BarChart[data, BarStyle :> colortable, Ticks -> tickstable, BarGroupSpacing -> 0] you will get your desired result with the exception, that the value on the x-axes will be printed under each column. Another way is to use GeneralizedBarChart : In[..]:=data = Range[13]; In[..]:=boxdata = Table[{i, data[[i]], 1}, {i, 1, 13}]; In[..]:=colortable = Table[Table[RGBColor[i, 1 - i, 0], {3}], {i, 0, 1, .3}] // Flatten; In[..]:=tickstable = {Table[{i - 1, i/3}, {i, 3, 13, 3}], Automatic}; In[..]:=GeneralizedBarChart[data2, BarStyle -> colortable, Ticks -> tickstable] ... Look the help browser for Ticks, FrameTicks, BarStyle, PlotStyle ... -- Christoph Lhotka -- University of Vienna Institute for Astronomy Tuerkenschanzstr. 17 1180 Vienna, Austria fon. +43.1.4277.518.41 mail. lhotka at astro.univie.ac.at