How to mask a data using the contour closed line?

I have a lower resolution data. If I do masking using shapefile some portion around the boundary is getting cut. I just want to mention I don't want to interpolate.
Therefore, I am looking a for a solution where I can mask the data using contour lines itself. Regardless of whether a whole/half pixel coming inside of it. I want to show even a small portion of the pixel coming inside of it. I also don't want to show anything outisde the contour line.
I hope you could understand what I am looking for. You can see a figure attached below. You could see a Indian boundary contour, I just want to make outside that region white insider the rectangle box. Other things (colorbar,xticks,yticks) I want to keep at it's.
Looking forward to your suggestion.
Thanks in advance.

回答 (1 件)

KSSV
KSSV 2022 年 7 月 10 日

0 投票

Read about inpolygon. Using this you can get the indices lying inside and outside the closed shape. Using tese indices you can make the puter points NaN and the plot.

3 件のコメント

Subhodh Sharma
Subhodh Sharma 2022 年 7 月 10 日
@KSSV I have tried this one. My data resolution is 2.5 deg (coarse resolution). If I consider all points in and on both are coming but when I am plotting the contourf some pixels eventually goes outside the Indian boundary. I want to smoothly mask around the boundary. If I consider masking using grid then it's hard road to what I want. I hope you have understood my requirement.
Image Analyst
Image Analyst 2022 年 7 月 10 日
Tell us exactly what functions and arguments you used to display the image and the black outline.
Subhodh Sharma
Subhodh Sharma 2022 年 7 月 11 日
@Image Analyst This is simple contourf plot (i.e., contourf(lon,lat,data)). And the black outline is just line plot made using plot function (like plot(lon,lat)).

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Contour Plots についてさらに検索

質問済み:

2022 年 7 月 10 日

コメント済み:

2022 年 7 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by