2D density plot with colorbar

7 次查看(过去 30 天)
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 中查找有关 Formatting and Annotation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by