How do I replace NaN values in contourf with another plot?
이전 댓글 표시
I am using contourf to plot salinity over a large region. Data only shows over ocean, so I was hoping to show an outline of the shoreline where NaN values appear on the contour. I've created a representative example in the following code:
X=rand(30,60);
X(10:25,10:30) = NaN;
figure();
subplot(2,1,1)
load coast;
lat2=[nan;lat;nan; lat];
long2=[nan;long; nan; long+360];
plot(long2,lat2,'k','linewidth',1)
axis([260 320 0 30]);
subplot(2,1,2)
contourf(X)
This example creates two subplots: the first shows the shorelines, the second shows contours with a hole (due to NaN values). I want to create one plot that shows the filled contours on top with the shorelines peaking through the hole.
I have tried making the NaN values transparent, but wasn't getting anywhere. Any help would be greatly appreciated!
댓글 수: 2
Star Strider
2016년 10월 14일
Are you going to share ‘coast’, ‘lat’ and ‘lon’ with us?
Does this require the Mapping Toolbox? If so, please add that in the Product Tags.
Also, your axis call is perplexing, because ‘0’ and ‘30’ as integers can be represented exactly in binary form. No rounding is necessary.
Jonathan Whiting
2016년 10월 17일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Vector Fields에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!