
how can i create a horizontal bar plot and label in each stack
    5 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    TESFALEM ALDADA
 am 22 Nov. 2020
  
    
    
    
    
    Bearbeitet: Scott MacKenzie
      
 am 12 Mai 2021
            I have ahorizontal two stacked bar plots, for the data shown below.
i want to label on the stacks & the thickness of the bar
Note: the figure i want to produce is shown on figure 1, but MATLAB produces the one shown on figure 2
a1=[51.2	1.6	8.7	9.9	1.1	26.0	1.5	0.0
    25.5	0.0	0.3	7.9	0.0	58.6	5.4	2.3];
barh(a1,'stacked')
legend('1','2','3','4','5','6','7','8')
set(gca,'yticklabel',{'1996','2017'})

0 Kommentare
Akzeptierte Antwort
  Scott MacKenzie
      
 am 12 Mai 2021
        
      Bearbeitet: Scott MacKenzie
      
 am 12 Mai 2021
  
      a1=[51.2, 1.6, 8.7, 9.9, 1.1, 26.0, 1.5, 0.0;
    25.5, 0.0, 0.3, 7.9, 0.0, 58.6, 5.4, 2.3];
b = barh(a1,'stacked', 'edgecolor', 'flat');
legend('1','2','3','4','5','6','7','8');
set(gca,'yticklabel',{'1996','2017'});
% add data value to middle of each bar (Note: x and y reversed)
for i=1:length(b)
    for j = 1:length(b(i).YData)
        y = b(i).YEndPoints(j) - (b(i).YData(j)) / 2;
        s = sprintf('%.1f', b(i).YData(j));
        text(y, b(i).XData(j), s);
    end
end

0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!