Represent data with a status bar plot
4 views (last 30 days)
Show older comments
Hello everyone!
I'm looking for a way to represent my data in the form of a status bar, the colour of which depends on the value.
The end result should look something like this

Does anyone know the function that plots something like this?
0 Comments
Accepted Answer
Voss
on 4 Mar 2025
t = load('mydata.mat').mydata;
X = repmat(double(t.Time(:)),1,2);
C = repmat(double(t.Data(:)),1,2);
Y = zeros(size(X))+[0 1];
figure('Position',[1 1 900 600])
tiledlayout(2,2)
nexttile
plot(t.Time,t.Data)
xlim(t.Time([1 end]))
title(sprintf('line plot:\nentire timeseries'))
nexttile
plot(t.Time,t.Data)
xlim([0 40])
title(sprintf('line plot:\nzoomed to beginning'))
nexttile
surface(X,Y,C,'EdgeColor','none')
xlim(X([1 end],1))
ylim(Y(1)+[-0.5 1.5])
colorbar
title(sprintf('status-bar plot:\nentire timeseries'))
nexttile
surface(X,Y,C,'EdgeColor','none')
xlim([0 40])
ylim(Y(1)+[-0.5 1.5])
colorbar
title(sprintf('status-bar plot:\nzoomed to beginning'))
4 Comments
Voss
on 5 Mar 2025
Here's one approach you can use to add the enumerated data (text objects):
t = load('mydata.mat').mydata;
X = repmat(double(t.Time(:)),1,2);
C = repmat(double(t.Data(:)),1,2);
Z = zeros(size(X));
Y = Z+[0 1];
[G,GID] = findgroups(t.Data);
NG = numel(GID);
XT = zeros(NG,1);
for ii = 1:NG
XT(ii) = mean(t.Time(G == ii));
end
YT = (Y(1,1)+Y(1,2))/2*ones(NG,1);
ST = string(GID);
args = {'HorizontalAlignment','center','Color','w','FontSize',14};
figure('Position',[1 1 900 600],'Color',[0.94,0.94,0.94])
tiledlayout(2,1)
nexttile
surface(X,Y,Z,C,'EdgeColor','none')
text(XT,YT,ST,args{:})
xlim(X([1 end],1))
ylim(Y(1,:)+[-0.5 0.5])
colorbar
title(sprintf('status-bar plot:\nentire timeseries'))
nexttile
surface(X,Y,Z,C,'EdgeColor','none')
text(XT,YT,ST,args{:})
xlim([0 40])
ylim(Y(1,:)+[-0.5 0.5])
colorbar
title(sprintf('status-bar plot:\nzoomed to beginning'))
More Answers (1)
Aquatris
on 4 Mar 2025
You can use bar() function with 'stacked' argument;
y = [30 50 10 10];
barh(1,y,"stacked");
2 Comments
See Also
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!