how to label multiple bars within the same x-value

13 Ansichten (letzte 30 Tage)
Joakim Mørk
Joakim Mørk am 5 Mai 2020
Beantwortet: Joakim Mørk am 6 Mai 2020
Hej im trying to create a plot of some testvalues, and i simply cant figure out a way to label multiple bars within the same x-value.
The test data comes out in a 6 x M matrix telling the time datacollection time and a 4 x M matrix with the testdata were each column is zone1, zone2, zone3 and zone4.
i've tried this so far:
Zones={'zone1','zone2','zone3','zone4'};
X=tvec_a(:,4);
Y=data_a;
bar(X,Y,1)
set(gca,'xticklabel',Zones)
title('Hourly consumption')
xlabel('Hour')
ylabel('Consumption')
But this simply output all four columns with the same same instead of each column was devided into zones for each x-val:

Akzeptierte Antwort

Joakim Mørk
Joakim Mørk am 6 Mai 2020
After a whole lot of research, I've found nothing that solves that excact problem. Allthough I ended up finding two solutions wich solves the issue of telling the individual bars from oneanother:
1) using legend:
b=bar(tvec_a(:,N),data_a,1);
title(name)
xlabel(X)
ylabel('Consumption')
axis([-inf inf -inf inf])
legend({'zone 1','zone 2', 'zone 3', 'zone 4'},'Location','northwest')
grid on
2) using bar labels
b=bar(tvec_a(:,N),data_a,1);
title(name)
xlabel(X)
ylabel('Consumption')
xtips1 = b(1).XEndPoints;
ytips1 = b(1).YEndPoints;
labels1 = 'z_1';
text(xtips1,ytips1,labels1,'HorizontalAlignment','center',...
'VerticalAlignment','top','color','w')
xtips2 = b(2).XEndPoints;
ytips2 = b(2).YEndPoints;
labels2 = 'z_2';
text(xtips2,ytips2,labels2,'HorizontalAlignment','center',...
'VerticalAlignment','top','color','w')
xtips3 = b(3).XEndPoints;
ytips3 = b(3).YEndPoints;
labels3 = 'z_2';
text(xtips3,ytips3,labels3,'HorizontalAlignment','center',...
'VerticalAlignment','top','color','w')
xtips4 = b(4).XEndPoints;
ytips4 = b(4).YEndPoints;
labels4 = 'z_2';
text(xtips4,ytips4,labels4,'HorizontalAlignment','center',...
'VerticalAlignment','top','color','w')
axis([-inf inf -inf inf])
grid on
I personally thinks the legend is the better sollution

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Signal Processing Toolbox finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by