At the end of some data processing in MATLAB, I want to create a plot which shows colored timeline bars for a series of data. I have a number of processes which each go through similar steps, and start and stop and different at different times. Ideally it'd end up looking something like this (forgive the ASCII art):
| ###***$$$$$$$$$$ Process 1 | ###***$$$$$$$ Process 2 | ###$$$$$ Process 3 | *******$$$$$$ Process 4 +------------------------------------------ Time
Where #
*
and $
are standing in for solid, adjacent blocks of differing colors (one color per step the processes go through; note some are optional).
The labels could be elsewhere, but next to each line is good.
I have hacked together a solution using rectangle
and text
, but it seems like this might be an existing type of plot within MATLAB that I just haven't found yet. Do you know of one?
Use barh
. Set the first column as your initial process time
data_with_init_time = [
1, 10, 5, 3 ;
3, 10, 3, 9 ;
7, 10, 4, 8 ;
12,10, 2, 2 ];
h = barh(data_with_init_time, 'stack');
set(h(1), 'facecolor', 'none', 'EdgeColor', 'none'); % disable the color of the first column (init time)
set(gca, 'YTickLabel', {'proc 1', 'proc 2', 'proc 3', 'proc 4'} ); % change the y axis tick to your name of the process
axis ij; % Put the first row at top
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With