Histogram x axis range

조회 수: 492 (최근 30일)
Marimuthu Ananthavelu
Marimuthu Ananthavelu 2018년 12월 23일
댓글: Marimuthu Ananthavelu 2018년 12월 23일
I am trying to plot the Histogram for a matrix which contains the values ranging from 0 to 0.1. However I wish to have the X axis values ranging from 0 to 1 with 20 bins (with each of 0.05 value difference). This is for me to show how the overall distribution is still less than 0.1 in the whole range of 0 to 1.
I tried the following code, and however, this does not work as the Histogram always shrinks the X-axis with values less than 0.1 (due to the maximum value in the matrix).
edges = [0 1];
histogram('BinEdges',edges,'BinCounts',20)
histogram( data(:));
Any help is appreciated for me to achieve this goal. Thanks

채택된 답변

Image Analyst
Image Analyst 2018년 12월 23일
You can do this:
data = 0.1 * rand(1, 1000); % Create sample data.
edges = linspace(0, 1, 21); % Create 20 bins.
% Plot the histogram.
histogram(data, 'BinEdges',edges);
% Fancy up the graph.
grid on;
xlim([0, 1]);
xlabel('Data Value', 'FontSize', 14);
ylabel('Bin Count', 'FontSize', 14);
title('Histogram of Data', 'FontSize', 14);
0000 Screenshot.png
Of course you will have only 2 bins for your data to fall into, so I don't know if that's what you want.
  댓글 수: 1
Marimuthu Ananthavelu
Marimuthu Ananthavelu 2018년 12월 23일
편집: Marimuthu Ananthavelu 2018년 12월 23일
Thanks so much, yes thats what I expected to have. :)

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

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 12월 23일
h=histogram('BinEdges',edges,'BinCounts',20)
h.BinLimits=[0 1] % x-axis range
  댓글 수: 3
madhan ravi
madhan ravi 2018년 12월 23일
So remove BinCounts option and try?
Marimuthu Ananthavelu
Marimuthu Ananthavelu 2018년 12월 23일
Unfortunateley, that does not help. THanks so much.

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

카테고리

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

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by