Bar plot with two x axis and Display Groups of Bars
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rachele Franceschini
am 21 Mai 2022
Kommentiert: VBBV
am 30 Mai 2022
I have this script, for creating bar plot with two different x axes. But I get a bar plot with overlay.
I would like bar one next to the other.
See image
subplot(3,2,1)
x = tabellapermatlab.Year;
y = tabellapermatlab.News12;
yyaxis left
%ax = gca;
%ax.YAxis.Exponent = 2;
bar(x,y,'yellow')
title('Variable news')
ylabel('count','FontSize',12)
hold on
x=tabellapermatlab.Year;
y6=tabellapermatlab.somma_noti;
yyaxis right
bar(x,y6,0.3)
%ax.YAxis.Exponent = 3;
title('Variable news1')
ylabel('count','FontSize',12)
hold off
0 Kommentare
Akzeptierte Antwort
VBBV
am 21 Mai 2022
Bearbeitet: VBBV
am 21 Mai 2022
x = 2010:2019;
y = rand(1,10); % 1
y6= rand(1,10); % 2
yyaxis left
%ax = gca;
%ax.YAxis.Exponent = 2;
b = bar(x,[y;y6]);
b(1).FaceColor = [1 0 0];
b(2).FaceColor = [1 1 0];
title('Variable news')
ylabel('count','FontSize',12)
you can use the handle to bar function and set the color you want using RGB triplet values
4 Kommentare
Rachele Franceschini
am 23 Mai 2022
Bearbeitet: Rachele Franceschini
am 23 Mai 2022
VBBV
am 30 Mai 2022
Yes. I think it works for 2 different y axes and it's shown clearly in my code output
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Line 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!