Stacked bar plot for individual object accumulation in a date series

1 次查看(过去 30 天)
I would represent my data in a bar graphic.
Imagine this situation:
01/01/2009 - 'wake up' - 'breakfast' - 'work' - 'sleep'
02/01/2009 - 'wake up' - 'work' - 'sleep'
03/01/2009 - 'wake up' - 'pray' - 'dinner' - 'sleep' ...
I would be able to have a bar graph, like stack bar in which I can have the daily succession of this, not numeric values. I would have, for each day a multicolor bar that represent, for each color, different actions.

回答(4 个)

Laura Proctor
Laura Proctor 2011-3-17
It seems like a bar chart may not be what you are looking for, but I envision the following code as a launching point for you:
x = [ 2 1 6 0 0 1
2 0 7 0 0 1
2 0 0 5 2 1 ];
bar(x,'stacked')
where the columns in x represent a different activity and each row represents a day. I ensured that the rows all equaled the same value so that each "day" has the same length.
  1 个评论
fabius
fabius 2011-3-18
Thank you,
I tried this way, but cyclist had a good suggestion with binary values. in this way I can do as you suggested me, but with equal ranges in bar chart.
If you have some suggestion for a better rappresentation than bar chart, I'll appreciate.
thank you a lot.

请先登录,再进行评论。


the cyclist
the cyclist 2011-3-17
Here is a start on how you could do this. Each activity is encoded into a binary yes/no bar of equal length.
Each row of the array "b" corresponds to a day, and each column is a binary value of whether or not the activity occurred that day.
I expect that a bar chart is not the best way to display these data, but that is for you to decide.
activity = {'wake up','breakfast','work','pray','dinner','sleep'};
b = [1 1 1 0 0 1; ...
1 0 1 0 0 1; ...
1 0 0 1 1 1];
figure
bar(b,'stacked')
legend(activity)
  2 个评论
fabius
fabius 2011-3-18
Tanks! is what I looked for.
if you have some suggestion for a better rappresentation than bar chart, please, tell me.
fabius
fabius 2011-3-18
I was too happy..
but there is an unsolved problem,
I used a wrong example, because in this case is due that first of all I must "wake up", in other way the rotation of actions is always the same.
I need a rappresentation also if I invert some action, in other way I need to rappresent different actions in different rotation to examine the order of actions in different days..
sorry... :(

请先登录,再进行评论。


fabius
fabius 2011-3-18
I was too happy.. but there is an unsolved problem, I used a wrong example, because in this case is due that first of all I must "wake up", in other way the rotation of actions is always the same. I need a rappresentation also if I invert some action, in other way I need to rappresent different actions in different rotation to examine the order of actions in different days.. sorry... :(

the cyclist
the cyclist 2011-3-20
In a stacked bar chart, the colors will always appear in the same order (unless they are absent altogether).
The only way I can think of to get what you want is to manually fill in rectangles according to the schedule, using the patch command. Here's a very simple example of using patches to paint rectangles on a set of axes:
figure
axis
patch([0 1 1 0],[0 0 1 1],'r');
patch([1 2 2 1],[0 0 1 1],'b');
patch([0 1 1 0],[1 1 2 2],'g')
See "help patch" for more details.

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by