필터 지우기
필터 지우기

2D density plot with colorbar

조회 수: 8 (최근 30일)
Farai Mahachi
Farai Mahachi 2019년 5월 9일
편집: Farai Mahachi 2019년 5월 9일
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

채택된 답변

KSSV
KSSV 2019년 5월 9일
편집: KSSV 2019년 5월 9일
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
Farai Mahachi
Farai Mahachi 2019년 5월 9일
편집: Farai Mahachi 2019년 5월 9일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by