2D density plot with colorbar
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi guys,
I have data which has produced a 2D plot as shown in the first figure.
![result_3.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/218691/result_3.jpeg)
How can I transform the above figure to appear like the one below?
![result_4.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/218692/result_4.png)
0 commentaires
Réponse acceptée
KSSV
le 9 Mai 2019
Modifié(e) : KSSV
le 9 Mai 2019
N = 100 ;
x = linspace(0,2*pi,N)' ;
y = sin(x) ;
xi = linspace(min(x),max(x),N) ;
yi = linspace(min(y)-1,max(y)+1,N) ;
[X,Y] = meshgrid(xi,yi) ;
Z = zeros(size(X)) ;
idx = knnsearch([X(:) Y(:)],[x y]) ;
Z(idx) = 1 ;
Z(idx+1) = 1 ;
Z(idx-1) = 1 ;
pcolor(X,Y,Z)
shading interp
colorbar
colormap(jet)
1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Time-Frequency Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!