# how do I convert scatter data into a density plot

194 Ansichten (letzte 30 Tage)
Howard Padmore am 4 Jul. 2023
Beantwortet: Emma Farnan am 1 Mär. 2024
I have scatter data in an x and y array. Using Scatter this produces dots at the x,y coordinate.
How do I convert this to a density map (I will have many more points). I could do this by splitting the space into a number of bins of a defined size and then count the number of points that fell inside each, then I would have x',y',z data, but there must be a Matlab function for this
Typical scatter plot is
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Howard Padmore am 5 Jul. 2023
thanks for the suggestion. Histcounts2 worked perfectly. Only issue is that the routine gives the edge positions of each bin as two vectors, and then an array of intensities, so you end up with 1 more position in each vector than histogram bins along each axis. I averaged adjacent bin edge positions, so this gives the same number of positions in the x-y vectors as values in the x-y array. Then you can use mesh or surface to view the density plot. Many thanks for the help.

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Diya Tulshan am 4 Jul. 2023
I understand that you want to know about the MATLAB function to convert scatter data into density plot.
Kindly refer to the following documents for implementing the plot:-
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (2)

Nikhil am 4 Jul. 2023
Hey Howard,
After searching about your issue and I think that density plots using hist3 and contourf will be helpful.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Emma Farnan am 1 Mär. 2024
Depending on how close your points are and their original size, you could just use the additive opacity from MarkerFaceAlpha to give some intuition of the density.
x = randn(10000,1);
y = randn(10000,1);
figure; s = scatter(x,y,'filled','MarkerFaceAlpha',0.05);
Or alternatively, you could get a smoother version of the the histograms by using kernel density estimation (ksdensity) to predict the probability distribution. The example page shows how it can be used to plot a 3D meshgrid of the point density.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Scatter Plots finden Sie in Help Center und File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by