How can I set the histogram width?

조회 수: 5 (최근 30일)
Ilaria Sani
Ilaria Sani 2012년 10월 13일
댓글: Ashim 2014년 2월 5일
I would like to set the histogram width in hist(), can anyone help? Thanks

채택된 답변

Wayne King
Wayne King 2012년 10월 16일
편집: Wayne King 2012년 10월 16일
It sounds like what you want to do is return the counts and bin centers from hist(). In other words, do not plot with hist(), rather user bar() to plot. The third input argument to bar() is the bar width.
[N,X] = hist(randn(1000,1));
bar(X,N,0.5)
% the input 0.5 controls the bar width, it defaults to 0.8
  댓글 수: 2
Ilaria Sani
Ilaria Sani 2012년 10월 16일
Thanks. What I wanted to ask was a purely "graphical question". hist() is more efficent than bar() in plotting a distribution because it allows bin settings, but I guess it doesn't allow graphical column-width setting.
Ashim
Ashim 2014년 2월 5일
I have a question on the answer. i don't think we can set the width if we use the option in bar graph to use 'histc'. i want to end up in a histogram grouped together, with white background and a width of 0.3 but i can get them all at a time. Although this worked, but cannot adjust the width of the bar columns.
if true
% code
hist(WS,bins,'w');
h = findobj(gca, 'Type', 'patch');
set(h, 'FaceColor', 'w');
end

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

추가 답변 (4개)

Wayne King
Wayne King 2012년 10월 13일
If by histogram width, you mean the width of the bins, then you can do that by specifying the number of bins you use as an input argument; this is documented.
Or use histc() and specify the edges as a vector input.

Ilaria Sani
Ilaria Sani 2012년 10월 13일
Sorry, with with I meant the width in the plot. So it's a"graphical" question.

Wayne King
Wayne King 2012년 10월 13일
편집: Wayne King 2012년 10월 13일
You can simply modify the width of the plot
hist(randn(1000,1))
ax = gca;
get(ax,'position')
Now you'll see a vector with 4 elements. The 4 elements are
[left bottom width height]
so add to the width value. You'll probably want to reduce the left value as well to keep the histogram "centered"

Ilaria Sani
Ilaria Sani 2012년 10월 15일
I have tried to modify the vector from the menu "more proprieties". I can modify it, but nothing happens to the columns, no visual changes; the only one effect is a larger or narrower figure outline.
In other words: given this hstogram
hist([randn(1000,1), randn(1000,1)])
I don't want the coulmns to be so narrow and separated, how can I change this?
Thanks a lot.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by