登录论坛

查看完整版本 : 在MATLAB中创建“时间轴”样式的图形


poster
2019-12-10, 20:48
在MATLAB中进行一些数据处理的最后,我想创建一个图,该图显示一系列数据的彩色时间轴条。我有许多流程,每个流程都经过相似的步骤,并且开始和停止的时间不同。理想情况下,它最终看起来像这样(原谅ASCII艺术):

| ### *** $$$$$$$$$$$ Process 1 | ### *** $$$$$$$ Process 2 | ### $$$$$处理3 | ******* $$$$$$$处理4 + ------------------------------------------ 时间其中# *和$代表相邻的不同颜色的单色块(过程经历的每一步一种颜色;请注意,有些是可选的)。

标签可以在其他地方,但是每行旁边都不错。

我已经用rectangle和text破解了一个解决方案,但是似乎这可能是我尚未发现的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

更多&回答... (https://stackoverflow.com/questions/3373425)