Graphics 创建一个';时间线';MATLAB中的图形样式

Graphics 创建一个';时间线';MATLAB中的图形样式,graphics,matlab,Graphics,Matlab,在MATLAB中的一些数据处理结束时,我想创建一个图,显示一系列数据的彩色时间线条。我有很多流程,每个流程都经历了相似的步骤,在不同的时间启动和停止。理想情况下,它最终会看起来像这样(请原谅ASCII艺术): |###***$$$$$$$$$进程1 |###***$$$$$$$进程2 |###$$$$进程3 |******$$$$$$进程4 +------------------------------------------ 时间 其中,#*和$代表不同颜色的实心相邻块(过程中每个步骤使用一种

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

|###***$$$$$$$$$进程1 |###***$$$$$$$进程2 |###$$$$进程3 |******$$$$$$进程4 +------------------------------------------ 时间 其中,
#
*
$
代表不同颜色的实心相邻块(过程中每个步骤使用一种颜色;注意,有些是可选的)

标签可以在其他地方,但每行旁边都是好的


我已经用
矩形
文本
拼凑出了一个解决方案,但似乎这可能是MATLAB中现有的绘图类型,我还没有找到。你知道吗?

使用
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

+1:很好,不过我可能会稍微修改一下。默认情况下,轴的背景色通常为白色,但如果不是,您可以这样做:
axesColor=get(gca,'color');设置(h(1),‘面色’、AxeColor、‘边色’、AxeColor)
@gnovice:您可以简单地将颜色设置为
'none'
@Amro:啊,是的。我完全忘了这对条形图有用。这是一个更好的选择。谢谢你们的提示。您的评论已整合到答案中。我刚刚发现“axis ij”可能会以首选顺序显示数据。我也刚刚想到,您可以使用
set(h(1),“Visible”,“off”)
而不是“none”颜色,特别是如果您希望第一个系列根据
ColorOrder
属性匹配当前颜色映射中的第一种颜色(否则将跳过第一个)
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