在MATLAB中创建"时间轴"样式图形

Ale*_*man 6 graphics matlab

在MATLAB中的一些数据处理结束时,我想创建一个图表,显示一系列数据的彩色时间轴条.我有许多流程,每个流程都经历类似的步骤,并且在不同的时间启动和停止并且不同.理想情况下,它最终看起来像这样(原谅ASCII艺术):

   |   ###***$$$$$$$$$$         Process 1
   |        ###***$$$$$$$       Process 2
   |           ###$$$$$         Process 3
   |             *******$$$$$$  Process 4
   +------------------------------------------
                    Time

在哪里# *$哪些站立的是不同颜色的固体相邻块(每个步骤一个颜色,过程经过;注意一些是可选的).

标签可能在其他地方,但每条线旁边都很好.

我使用rectangle和已经破解了一个解决方案text,但似乎这可能是MATLAB中现有的一种情节,我还没有找到.你知道吗?

YYC*_*YYC 9

使用barh.将第一列设置为初始处理时间

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
Run Code Online (Sandbox Code Playgroud)

  • @gnovice:您可以简单地将颜色设置为"无" (2认同)
  • 也刚刚发生在我身上,你可以使用`set(h(1),'Visible','off')`而不是'none'颜色,特别是如果你想让第一个系列与当前色图中的第一个颜色相匹配到'ColorOrder`属性(否则会跳过第一个属性) (2认同)