Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I would like to do is represent the state of a machine over a period of time using a RectangleChart (or anything else that can do it) . The chart will need to be made up of equally sized blocks that change colour based on the state of the machine (there are 7 states 1-7) at that time.

I've created this chart which is similar to what I want;

data = Table[{RandomInteger[{1, 7}], 5}, {i, 1, 20}];
RectangleChart[data, ChartLayout -> "Stacked", BarOrigin -> Left]

Almost what I'm after

The problem with this chart is my state data is being represented by the height of the bar, not the colour.

What is the best way to get the results I'm after?

share|improve this question
"Possible settings for ChartLayout include "Grouped" and "Stepped". You will need to revert to BarChart if you want it stacked – Mike Honeychurch Nov 15 '12 at 4:14
up vote 3 down vote accepted

If you have to use RectangleChart, then you can do something like

   states = Transpose[data][[1]]; 
 RectangleChart[ConstantArray[{1, 1}, {20}], ChartLayout -> "Stacked", 
    BarOrigin -> Left,  ChartStyle -> (Hue[#/7] & /@ states)]


    {ConstantArray[{1, 1}, {20}], Hue[#/7] & /@ states}], 
    ChartLayout -> "Stacked", BarOrigin -> Left]

to get

enter image description here

Among many other alternatives, ArrayPlot is probably one of the simplest ones to use:

 ArrayPlot[{states}, ColorFunction -> "TemperatureMap", 
   FrameTicks -> {{None, None}, {Automatic, None}}]

enter image description here

share|improve this answer
Thanks kguler, I think ArrayPlot is what I'm after. – Cam Nov 15 '12 at 5:03
@Cam, my pleasure. Thank you for the accept. – kglr Nov 15 '12 at 5:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.