フィルターのクリア

How do I label the bars in my histogram?

49 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
編集済み: MathWorks Support Team 2017 年 6 月 20 日
How do I label the bars in my histogram?
I would like to label the bars of my histogram plot that I created using HIST. I would like to add the count to the top of the bar.

採用された回答

MathWorks Support Team
MathWorks Support Team 2017 年 6 月 20 日
As of MATLAB R2017a, there is no built-in feature to add bin count labels to histogram plots. Although this is not a built-in feature of MATLAB, you may label the bars of your histogram by using the output of the HIST command to create text objects. The following is an example that you can use as a guide:
% Create random data for the sake of the example
data = 10*rand(1,100);
% Draw the histogram
hist(data);
% Get information about the same
% histogram by returning arguments
[n,x] = hist(data);
% Create strings for each bar count
barstrings = num2str(n');
% Create text objects at each location
text(x,n,barstrings,'horizontalalignment','center','verticalalignment','bottom')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by