Stacked bar plot for individual object accumulation in a date series
2 次查看(过去 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.
0 个评论
回答(4 个)
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.
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)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!