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

8 次查看(过去 30 天)
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 个评论
Chunru
Chunru 2021-12-24
编辑:Chunru 2021-12-24
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');

请先登录,再进行评论。

更多回答(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:

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by