Search code examples
matlabplotvisualizationdensity-plot

How to add density information to a 2D-plot in Matlab?


I have two vectors with more than 300,000 data points. The other vector denotes observed values for some physical quantity and the other denotes the predicted values for those quantities. I want to plot these values in a scatter plot, in order to see how well my predictions did.

Now my problem is that in many cases the values overlap because Matlab has to draw more than 300,000 of them on the same plot and the data points form together a big unicolored ellipse kind of form. A picture will explain this better:

enter image description here

This is a scatter plot of my predictions vs observations. Now you can see that the points overlap a lot. The blue line corresponds to Y = X line and in an ideal case many of my points should lie on this line.

Now my problem is that based on looking at this picture I can't say how many points are close to the line and how many aren't. It might be for example that there is a very high density of points close to the blue line and relatively few points not close to the line, but I can't see this from the picture, because the points overlap as a result of their large amount.

My question is: How can you add density information into the picture as for example in the following picture is demonstrated:

enter image description here

In the picture above, the darker the area is the higher density of data points there is on the area. How can I do this in Matlab? Can you perhaps use 2-dimensional histograms to achieve this or?...

Thank you for any help! =)


Solution

  • You might like to try this smoothed histogram plot from MATLAB Central File Exchange.