how to define global coastline shapefile (boundary line) for a pcolor plot of data having range from 0 to 360 instead of -180 to 180

14 ビュー (過去 30 日間)
Hello all,
I was juts doing some seasurface temperature plots which has the range longitude from 0 to 360, the sample plot and data set(a single year data file is shared since the entire data set is too large to share) is attached below.
I would like highlight the coastline for this plot, which i wasnt able to do.
  1 件のコメント
Umar
Umar 2024 年 7 月 28 日

Hi Muskula,

To accomplish your task,load the sea surface temperature data from the provided SST_1year.mat file.

load('SST_1year.mat');

Plot the sea surface temperature data with the longitude range from 0 to 360.

figure;

imagesc(lon, lat, sst_data);

colorbar;

xlabel('Longitude');

ylabel('Latitude');

title('Sea Surface Temperature Plot');

Then, highlight the coastline by overlaying a coastline map on your existing plot by using the coast function from the Mapping Toolbox if available.

% Check if Mapping Toolbox is available

if license('test', 'map_toolbox')

    hold on;
    coast = load('coast.mat');
    plot(coast.long, coast.lat, 'k'); % Plot coastline in black color
    hold off;

else

    disp('Mapping Toolbox is required to plot the coastline.');

end

To define a global coastline shapefile for a pcolor plot in Matlab with a data range from 0 to 360, you can adjust the longitude values of the coastline data. You need to shift the coastline data points that fall in the range of 180 to 360 to negative values by subtracting 360 from them. This adjustment aligns the coastline data with the desired longitude range. Here is a simple example to illustrate this adjustment:

% Load coastline data

load coast

% Adjust coastline data for range 0 to 360

coast(coast(:, 1) >= 180, 1) = coast(coast(:, 1) >= 180, 1) - 360;

% Plot pcolor with adjusted coastline

figure

pcolor(X, Y, C)

hold on

plot(coast(:, 1), coast(:, 2), 'k')

Hope this answers your questions. Good luck

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

回答 (1 件)

Muskula
Muskula 2024 年 7 月 28 日
Thank you Umar for your reply,
I have tried the way that you have mentioned but it displays the following error
Error using load
Unable to find file or directory 'coast.mat'
To add, the mapping tool box is already installed and I am using Matlab R2022b version does the version needed to be updated?
  11 件のコメント
Muskula
Muskula 2024 年 7 月 30 日
Hello Umar,
Thank you very much for your time and patience in addressing all my queries.
The issue is solved now, the problem was with my version of matlab, I updated to latest version and the issue is sorted now.
Thank you once again!
Umar
Umar 2024 年 7 月 30 日
Hi Muskula,
No problem, glad to help out. It’s a good sign that issue is resolved. Please let me know if you have any further questions.

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

カテゴリ

Help Center および File ExchangeGeographic Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by