I already get the bar graph but I want to display 'No data' for June and July and I would like to display the data label for each data for each month.
This is my coding,thank you.
Y=[-8.9663 -6.7126 -7.8211 -8.8894 -5.2922 NaN NaN -8.5105 -8.5261 -7.6346 -12.0376 -11.7094]
figure1 = figure;
axes1 = axes('Parent',figure1);
hold(axes1,'on');
bar(Y);
text('Parent',axes1,'Rotation',90,'String','No Data','Position',[6 NaN 0]);
text('Parent',axes1,'Rotation',90,'String','No Data','Position',[7 NaN 0]);
ylabel('Intensiti arus MCEJ1 pada tahun 2014');
xlabel('Bulan');
hold(axes1,'off');
set(axes1,'XAxisLocation','top','XTick',[1 2 3 4 5 6 7 8 9 10 11 12],...
'XTickLabel',...
{'Jan','Feb','Mar','Apr','Mei','Jun','Jul','Ogos','Sep','Okt','Nov','Dis'});

댓글 수: 1

dpb
dpb 2020년 12월 13일
"and I would like to display the data label for each data for each month."
Sorry, but I'm not sure what you're asking for here? You mean to add the Y value on the bar, maybe?

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

 채택된 답변

Cris LaPierre
Cris LaPierre 2020년 12월 13일

2 개 추천

Perhaps see this example: Specify Labels at the Ends of Bars

댓글 수: 2

Here's how I might recreate your code.
Y=[-8.9663 -6.7126 -7.8211 -8.8894 -5.2922 NaN NaN -8.5105 -8.5261 -7.6346 -12.0376 -11.7094];
X = categorical(["Jan","Feb","Mar","Apr","Mei","Jun","Jul","Ogos","Sep","Okt","Nov","Dis"]);
b = bar(X,Y);
axes1 = gca;
set(axes1,'XAxisLocation','top');
text(axes1,X(6),0,'No Data','Rotation',-90);
text(axes1,X(7),0,'No Data','Rotation',-90);
ylabel('Intensiti arus MCEJ1 pada tahun 2014');
xlabel('Bulan');
% Add Y labels
xtips1 = b(1).XEndPoints;
ytips1 = b(1).YEndPoints;
labels1 = string(b(1).YData);
text(xtips1,ytips1,labels1,'HorizontalAlignment','center','VerticalAlignment','top')
Thank you so much :))

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by