How to perform a scatter plot based on density in MATLAB?

10 visualizaciones (últimos 30 días)
How to perform a scatter plot based on density in MATLAB?
I have two vectors x & y and I am looking for a way to create a scatter plot of x & y based on their degree of closeness or density in MATLAB.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 31 de Oct. de 2017
The 'scatplot' command takes in column matrix x & y and performs a density based scatter plot as shown in this example:
>> x = randn(1,1000);
>> y = randn(1,1000);
>> scatplot(x,y);
>> colorbar;
The link to the 'scatplot' can be found here :
https://www.mathworks.com/matlabcentral/fileexchange/8577-scatplot
Another File Exchange function called 'dscatter' performs a similar plot.
The File Exchange link can be found here:
>> x = randn(1000,1);
>> y = randn(1000,1);
>> dscatter(x,y)
We can visualize the density within a grid in MATLAB by binning using the hist3 function and subsequently plotting it as follows: 
>> x = randn(1,1000);
>> y = randn(1,1000);
>> n = hist3([x', y']);
>> pcolor(n);
To query the coordinates for a color range, please refer the following:
The function 'getDataForColorRange' in the attachment accepts an Axes handle returned by the 'dscatter' function and a color range.
For example, let us plot the following:
>> x = randn(1000,1);
>> y = randn(1000,1);
>> f = dscatter(x,y);
>> colorbar;
We can query all the X and Y coordinates that are present in the color range 0.7 to 0.9 as follows:
>> [x,y,idx] = getDataForColorRange(f,[0.7 0.9]);
To view this data, we can update the scatter plot as follows:
>> c = f.Children;
>> c.CData(~idx) = NaN;

Más respuestas (0)

Categorías

Más información sobre Scatter Plots en Help Center y File Exchange.

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by