Choose the ideal number of bins in hist3

4 views (last 30 days)
Ricardo Duarte
Ricardo Duarte on 2 Dec 2022
Answered: Muskan on 4 Sep 2023
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 Comments
Ricardo Duarte
Ricardo Duarte on 3 Dec 2022
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 on 3 Dec 2022
What about a 2D interpolation with the smaller number of bins? This will keep the highest possible resolution for a 1-by-1 comparison.

Sign in to comment.

Answers (1)

Muskan
Muskan on 4 Sep 2023
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

Products

Community Treasure Hunt

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

Start Hunting!