How can i show only definite data values in bar plot?
25 ビュー (過去 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/842820/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/842885/image.jpeg)
0 件のコメント
採用された回答
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');
その他の回答 (1 件)
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');
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!