2D density plot with colorbar

7 Ansichten (letzte 30 Tage)
Farai Mahachi
Farai Mahachi am 9 Mai 2019
Bearbeitet: Farai Mahachi am 9 Mai 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

Akzeptierte Antwort

KSSV
KSSV am 9 Mai 2019
Bearbeitet: KSSV am 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 Kommentar
Farai Mahachi
Farai Mahachi am 9 Mai 2019
Bearbeitet: Farai Mahachi am 9 Mai 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Formatting and Annotation finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by