function fig_timing_attachment() %FIG_TIMING_ATTACHMENT 附件计时示例:逐动作的耗时构成(堆叠条形)与单步合计。 S = fig_style(); D = load_data(S, 'timing_attachment'); fig = figure('Color', 'w', 'Visible', 'off'); ax = axes(fig); n = numel(D.labels); Y = [D.move(:), D.switch_s(:), D.action(:)]; y = (n:-1:1)'; % 动作按先后从上到下排列 barh(ax, y, Y, 'stacked'); total = sum(Y, 2); xlim(ax, [0, max(total) * 1.18]); hold(ax, 'on'); for i = 1:n if total(i) > 0 text(ax, total(i) + max(total) * 0.02, y(i), ... sprintf('%.0f s', total(i)), 'VerticalAlignment', 'middle', ... 'Interpreter', 'none'); end end hold(ax, 'off'); set(ax, 'YTick', 1:n, 'YTickLabel', flipud(D.labels(:)), ... 'TickLabelInterpreter', 'none'); xlabel(ax, D.xlabel); legend(ax, D.legend); fig_save(fig, S, 'timing-attachment-example-105-111-194-199.png'); end