How to perform a scatter plot based on density in MATLAB?
10 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2017-10-31
回答: MathWorks Support Team
2018-1-3
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.
采纳的回答
MathWorks Support Team
2017-10-31
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;
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!