Bar plot with two x axis and Display Groups of Bars

조회 수: 26 (최근 30일)
Rachele Franceschini
Rachele Franceschini 2022년 5월 21일
댓글: VBBV 2022년 5월 30일
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

채택된 답변

VBBV
VBBV 2022년 5월 21일
편집: VBBV 2022년 5월 21일
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
Rachele Franceschini
Rachele Franceschini 2022년 5월 23일
편집: Rachele Franceschini 2022년 5월 23일
Sorry! I wanted to say: Ihave two different y axes with different measure unity. It is possible apply the same your script with this condition?
x=2010:2019
y=[2322,2259,1719,2795,2988,2637,2794,3197,4392,6775]
y6=[21807,19920,12749,10301,26662,20638,18892,16492,20380,6775]
VBBV
VBBV 2022년 5월 30일
Yes. I think it works for 2 different y axes and it's shown clearly in my code output

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by