How to normalize a histogram2 along one dimension?

14 views (last 30 days)
I have a large set of datapoints, say in vectors X and Y containing the real variables x and y. To study the dependency of these variables, I can draw something like scatter(X,Y). But a disadvantage of scatter is that if the amount of samples is very high, it will just draw a uniformly colored area.
Histogram2 provides an alternative, where bin heights or colors show the amount of counts or probability (or corresponding density) to have events in a given region.
Now, just doing histogram2(X,Y) does not provide a satisfying picture of 'what y values are expected to what extent for every x value', because X itself is not uniformly distributed; the histogram2 is peaked both in x and y instead of peaked along a trend line as function of x.
Is there a way to compensate for this? I mean so that for each value of x there is a separate normalized probability that y should be found in one of the entries. The standard bin width, which is constant, remains fine to me.

Answers (1)

Steven Lord
Steven Lord on 30 May 2018
It sounds like you want a binscatter plot. This function was introduced in release R2017b. Look at the "Change Color Map of Binned Scatter Plot" example on that documentation page and see if that looks like what you want.
Or if you're using release R2017a or later, perhaps a heatmap will show you the data in a form similar to what you described. You mentioned normalizing in one dimension, and for that see the "Normalize Colors Along Each Row or Column" example on the heatmap documentation page.

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!