Control histogram appearance: width of bars

Hi, I'm plotting the following histogram:
h1 = histogram(FIBR);
h1.Normalization = 'probability';
h1.BinWidth = 100;
I want to the bars to be thinner so I've called
h1 = histogram(FIBR,'BarWidth',0.5);
But I get the following error:
Error using histogram>parseinput (line 211)
Expected input to match one of these strings:
'BinEdges', 'BinLimits', 'BinLimitsMode', 'BinMethod', 'BinWidth', 'BusyAction', 'ButtonDownFcn', 'CreateFcn', 'Data', 'DeleteFcn', 'DisplayName', 'DisplayStyle',
'EdgeAlpha', 'EdgeColor', 'FaceAlpha', 'FaceColor', 'HandleVisibility', 'HitTest', 'Interruptible', 'LineStyle', 'LineWidth', 'Normalization', 'NumBins',
'Orientation', 'Parent', 'PickableParts', 'Selected', 'SelectionHighlight', 'Tag', 'UIContextMenu', 'UserData', 'Visible'
The input, 'BarWidth', did not match any of the valid strings.
Error in histogram (line 118)
[opts,args] = parseinput(args,~isempty(cax));
And I'm really confused because I'm following the manual:

 採用された回答

michio
michio 2016 年 9 月 26 日

1 投票

'BarWidth' option only applies to histograms of categorical data. Is your FIBR categorical or numerical?
The following is one of the example from the documentation:
A = [0 0 1 1 1 0 0 0 0 NaN NaN 1 0 0 0 1 0 1 0 1 0 0 0 1 1 1 1];
C = categorical(A,[1 0 NaN],{'yes','no','undecided'});
h = histogram(C,'BarWidth',0.5);
If FIBR is of some discrete values, you can convert it to categorical then use BarWith property.

4 件のコメント

odo22
odo22 2016 年 9 月 27 日
Thanks for your reply.
My data is numerical - is there any way I could convert it? Otherwise, I guess I can live with the bars as they are :S
odo22
odo22 2016 年 9 月 27 日
I tried to use
x = categorical(FIBR)
but I get the following error:
Can not create default category names. Use the CATEGORYNAMES input argument.
michio
michio 2016 年 9 月 27 日
編集済み: michio 2016 年 9 月 29 日
I see. Making your data into categorical in some way is one idea. Another possible workaround would be to use bar function after counting the number of elements in the bin. Example follows.
nbins = 10;
x = randn(10000,1);
[counts,edges] = histcounts(x,nbins);
center = 0.5*(edges(1:end-1)+edges(2:end));
bar(center, counts, 0.7);
odo22
odo22 2016 年 9 月 29 日
Worked - thanks a lot! :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Distribution Plots についてさらに検索

製品

質問済み:

2016 年 9 月 26 日

編集済み:

2016 年 9 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by