How to create curve in a plot scatter figure?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dennis Huver
le 30 Août 2017
Commenté : Dennis Huver
le 31 Août 2017
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/166957/image.jpeg)
I am trying to create a curve in the plot, to show me density of the data(the dots). The curve needs to go up/down according to the scatter density, so that I can see where is most dense, where least and so on. I hope you get the picture. Thanks
0 commentaires
Réponse acceptée
Steven Lord
le 30 Août 2017
Use histcounts to count how much data is located in each bin along the X axis. Use the counts and edges in creating your plot. Alternately, use histogram with 'DisplayStyle', 'stairs'.
3 commentaires
Plus de réponses (1)
José-Luis
le 31 Août 2017
Modifié(e) : José-Luis
le 31 Août 2017
Convoluted way just to avoid repeating Steven's answer:
data = randn(5000,2); %First column xData, second column yData
[f,x] = ecdf(data(:,2));
[n,c] = ecdfhist(f,x,200);
x_val = linspace(min(data(:,1)),max(data(:,1)),200);
plot(data(:,1),data(:,2),'k.','LineWidth', 2);
hold on;
plot(c,n.*3,'r--')
0 commentaires
Voir également
Catégories
En savoir plus sur Scatter Plots dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!