Azzera filtri
Azzera filtri

2D density plot with colorbar

8 visualizzazioni (ultimi 30 giorni)
Farai Mahachi
Farai Mahachi il 9 Mag 2019
Modificato: Farai Mahachi il 9 Mag 2019
Hi guys,
I have data which has produced a 2D plot as shown in the first figure.
result_3.jpg
How can I transform the above figure to appear like the one below?
result_4.png

Risposta accettata

KSSV
KSSV il 9 Mag 2019
Modificato: KSSV il 9 Mag 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 Commento
Farai Mahachi
Farai Mahachi il 9 Mag 2019
Modificato: Farai Mahachi il 9 Mag 2019
Thanks KSSV,
does this procedure work as well for plotting multiple images on the same plot using pcolour and hold on?
I have been trying that but cant seem to plot two or more plots on the same figure.
I basically took your code and assigned different variables.
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)
hold on
shading interp
colorbar
NN = 100 ;
xx = linspace(0,2*pi,NN)' ;
yy = cos(xx) ;
xi1 = linspace(min(xx),max(xx),NN) ;
yi1 = linspace(min(yy)-1,max(yy)+1,NN) ;
[XX,YY] = meshgrid(xi1,yi1) ;
ZZ = zeros(size(XX)) ;
idx1 = knnsearch([XX(:) YY(:)],[xx yy]) ;
ZZ(idx1) = 1 ;
ZZ(idx1+1) = 1 ;
ZZ(idx1-1) = 1 ;
pcolor(XX,YY,ZZ)
shading interp
colorbar
colormap(jet)
But cant seem to plot two plots on the same figure.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Time-Frequency Analysis in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by