不,colorbar 并不是一个进度条。你可以通过例如实现你想要的。使用area。请参阅代码中的 cmets 进行解释。
% generate some example data, probably you'd do this in the loop.
N = 100;
eig_vals = rand(1,N) + 2*sin((1:N)*pi/20);
% make colormap from red to green.
red = [1, 0, 0];
green = [0, 1, 0];
cmap = interp1([1, N], [red; green], 1:N);
cmap_nan = NaN(N, 3); % some colormap with NaNs as placeholder.
% Initialize the figure. I chose to use two subplots, one for the data,
% one for the progressbar. The data subplot spans 4 horizontal subplot
% 'positions', and the progressbar is plotted in the 5th subplot.
figure(1); clf;
ax(1) = subplot(1,5,1:4);
% initialize a scatter object.
s = scatter(1:N, zeros(N, 1), [], cmap_nan, 'filled');
% and set the axis limits to the range you expect
ax(1).XLim = [0 N];
ax(1).YLim = [min(eig_vals), max(eig_vals)];
% second subplot for the progressbar. Initially, I make N area plots, and
% set the FaceColors to white.
ax(2) = subplot(1,5,5);
a = area([1 2]+N, ones(2,N)/N, 'FaceColor', 'w', 'LineStyle', 'none');
% remove ticks and set YLim.
ax(2).XTick = [];
ax(2).YTick = [];
ax(2).YLim = [0 1];
% loop over data, or calculate data in the loop.
for k = 1:N
% code to calculate stuff?
% ...
% add the new data point in the scatterplot
s.YData(k) = eig_vals(k);
% set the color of the datapoint
s.CData(k, :) = cmap(k, :);
% and set the color of the appropriate face in the progressbar
a(k).FaceColor = cmap(k,:);
% update the figure:
drawnow
end
% That's it.