Choose the ideal number of bins in hist3

조회 수: 9 (최근 30일)
Ricardo Duarte
Ricardo Duarte 2022년 12월 2일
답변: Muskan 2023년 9월 4일
Dear all,
I want to plot a hist3 plot but i'm not sure which is the ideal number of bins that I would need to define.
I have two variables with 116640 x 1 size and I'm using the following line of code:
hist3([Var1, Var2],[200 200],'CDataMode','auto','EdgeColor','none');
In this case I'm using [200 x 200] number of bins but as I want to compare these results with others with different variable sizes I'm not sure how to get the ideal number of bins based on the matrix sizes.
Do you have any idea how to do this?
Thank you in advance
  댓글 수: 5
Ricardo Duarte
Ricardo Duarte 2022년 12월 3일
The problem is that I have two plots that i can not compare them because they have two different number of bins.
Please have a look on these two figures:
In this figure I have 120bins
and in this one I have 1000bins
Is there any way to find a good number of bins (let's say, that allow me to see something in the plots) to make possible this comparison?
Thank you
Jan
Jan 2022년 12월 3일
What about a 2D interpolation with the smaller number of bins? This will keep the highest possible resolution for a 1-by-1 comparison.

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

답변 (1개)

Muskan
Muskan 2023년 9월 4일
Hi Ricardo,
I understand that you're interested in learning more about selecting the appropriate number of bins when plotting the histogram using the "hist3" function.
You can consider the following approaches to help you choose an appropriate number of bins in the “hist3” function:
Sturges' formula: One approach is to use Sturges' formula, which estimates the number of bins based on the logarithm of the number of data points. The formula is numBins = ceil(1 + log2(numPoints))
Experimentation and visualization: If the above approach do not provide satisfactory results, you can experiment with different numbers of bins and visually inspect the resulting “hist3” plots. Start with a smaller number of bins and gradually increase it to see how the histogram representation changes. Make sure to choose a number of bins that captures the desired level of detail without being too coarse or too fine.
You can further refer to the documentation of the “hist3” function:
I hope the above information helps resolve your query.
Thanks

카테고리

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