Stacked bar plot for individual object accumulation in a date series

조회 수: 1 (최근 30일)
fabius
fabius 2011년 3월 17일
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