How can i show only definite data values in bar plot?

X=1:7;
Y=[100 50 35 20 8 7 6];
bar(Y);
text(X,Y,num2str(Y','%0.2f'),'HorizontalAlignment','center','VerticalAlignment','bottom');
I am getting all the data values here in the bar plot. But i want to show the values only for first 3 (100, 50, 35). is it possible?
in X axes: showing all values
Y axes: bar data will be plotted for all values, but data will be shown only for first 3 values.

 채택된 답변

Chunru
Chunru 2021년 12월 24일
X=1:7;
Y=[100 50 35 20 8 7 6];
idx = 1:3; % select data to plot
bar(X(idx), Y(idx));
text(X(idx),Y(idx),num2str(Y(idx)','%0.2f'),'HorizontalAlignment','center','VerticalAlignment','bottom');

댓글 수: 3

Arif Hoq
Arif Hoq 2021년 12월 24일
편집: Arif Hoq 2021년 12월 24일
Actually, forgot to add something in my quetion. I want to show all X axes data also.
in X axes: showing all values
Y axes: bar data will be plotted for all values, but data will be shown only for first 3 values.
like this figure:
X=1:7;
Y=[100 50 35 20 8 7 6];
idx = 1:3; % select data to plot
bar(X, Y);
text(X(idx),Y(idx),num2str(Y(idx)','%0.2f'),'HorizontalAlignment','center','VerticalAlignment','bottom');
thank you very much @Chunru. it was my expectation.

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

추가 답변 (1개)

Voss
Voss 2021년 12월 24일
X=1:3;
Y=[100 50 35]; % 20 8 7 6];
bar(Y);
text(X,Y,num2str(Y','%0.2f'),'HorizontalAlignment','center','VerticalAlignment','bottom');

댓글 수: 1

Arif Hoq
Arif Hoq 2021년 12월 24일
편집: Arif Hoq 2021년 12월 24일
actually not like that. i am aware of that code.
could you please check my previous comment ?
I want to plot like this:

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

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

질문:

2021년 12월 24일

댓글:

2021년 12월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by