How to align the x axis of bar graphs in R2018b

조회 수: 11 (최근 30일)
Sridev Satpathy
Sridev Satpathy 2018년 11월 28일
댓글: Sridev Satpathy 2018년 12월 18일
The bar plots in the Matlab version 2018 doesnot align with the x - axis labels as was in the previous version. How can this be corrected? Attached plots from both versions for reference.
Version 2017:
Version R2018b:
  댓글 수: 3
Sridev Satpathy
Sridev Satpathy 2018년 11월 29일
Hello Cris,
Below is an extract of the code. There has been no changes to the code, only an upgrade of the matlab version. Look forward to your feedback.
Thanks
Sridev
******
Turbocharger_rpm_dev_trend =[1 2 3 1 2 3 ; 2 1 3 2 2 1];
Scavenge_pressure_dev_trend = [1 1 2 1 2 3];
Compare_months = {'May','Jun','Jul','Aug','Sep','Oct'};
h_ax(1) = subplot(211);
bar(Turbocharger_rpm_dev_trend','barwidth', 0.5);
ylabel('%','FontSize',10)
title('T/C rpm deviation from nominal')
legend('T/C # 1','T/C # 2','Orientation','horizontal')
set(gca,'xtick',[1:length(Compare_months)],'xticklabel',Compare_months)
grid on
h_ax(2) = subplot(212);
bar(Scavenge_pressure_dev_trend, 'FaceColor',[0 .5 .5],'barwidth', 0.5);
ylabel('bar','FontSize',10)
title('Scavenge pressure deviation from nominal')
set(gca,'xtick',[1:length(Compare_months)],'xticklabel',Compare_months)
grid on
Sridev Satpathy
Sridev Satpathy 2018년 12월 17일
Hello Chris,
Any update? Appreciate your input.
Thanks
Sridev

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

채택된 답변

Cris LaPierre
Cris LaPierre 2018년 12월 18일
I can't explain why behavior has changed, but I see what is happening. The xlim of your plots is different.
  • xlim - T/C rpm: [ 0.5571 6.4429]
  • xlim - Scavange pressure: [-0.0500 7.0500]
There are two ways around it that I've tested.
  1. Set xlim to be the same in both plots: xlim([0,7])
  2. include the months as the X variable when you call the bar function.
m = categorical({'Apr','May','Jun','Aug','Oct','Nov'});
Compare_months = reordercats(m,{'Apr','May','Jun','Aug','Oct','Nov'});
...
subplot(211);
bar(Compare_months,Turbocharger_rpm_dev_trend','barwidth', 0.5);
ylabel('%','FontSize',10)
title('T/C rpm deviation from nominal')
legend('T/C # 1','T/C # 2','Orientation','horizontal')
grid on
barAlignmentV2.png

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by