2D density plot with colorbar
조회 수: 8 (최근 30일)
이전 댓글 표시
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
채택된 답변
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!