How to draw streamline in a map?

5 次查看(过去 30 天)
Zijia Zheng
Zijia Zheng 2021-11-21
Hello! I want to ask how to draw some streamlines in a map by using the function 'streamslice' and the m_map package?

回答(1 个)

Simran
Simran 2025-2-18
I see you want to draw some streamlines in a map by using the “streamslice” and the “m_map” package. To do so follow these steps:
1.) Ensure you have the m_map package installed and added to your MATLAB path. You can refer to this link for help with this:
2.) If that is done, make sure you have your vector field data, in the form of “U” and “V” velocity matrices along with corresponding latitude and longitude grids.
3.) Next use the “m_map” package to create a map projection and display the base map.
4.) Use the “streamslice” function to overlay streamlines on the map.
Below I have used an example with some random data to show you how it works:
% Example Data
% Define a grid of latitude and longitude
lat = linspace(-10, 10, 100); % Latitude from -10 to 10 degrees
lon = linspace(-20, 20, 100); % Longitude from -20 to 20 degrees
[Lon, Lat] = meshgrid(lon, lat);
% Define synthetic vector field data (U, V)
% U and V represent the eastward and northward components of the velocity
U = cosd(Lat) .* sind(Lon); % Eastward component
V = sind(Lat) .* cosd(Lon); % Northward component
% Set up the map using m_map
m_proj('mercator', 'lat', [min(lat) max(lat)], 'lon', [min(lon) max(lon)]);
m_coast('patch', [0.7 0.7 0.7]); % Add coastlines with a gray patch
m_grid('box', 'fancy', 'tickdir', 'in'); % Add a grid with fancy box style
% Convert lat/lon to map coordinates
[X, Y] = m_ll2xy(Lon, Lat);
% Plot streamlines using streamslice
hold on;
h = streamslice(X, Y, U, V); % Plot streamlines
set(h, 'Color', 'r'); % Set streamline color to red
% Add additional plot elements if needed
title('Streamlines on Map');
And this was the result with streamlines on the map as you can see.
For more information, you can refer to these documentations:
Installing “m_map” package- https://www-old.eoas.ubc.ca/~rich/map.html
  1 个评论
Zijia Zheng
Zijia Zheng 2025-2-26
Hi, @Simran, thank you so much for the answer.
You showed a perfect example in the low-latitdue area.
However, when I change the latitude to the Arctic area and use the lambert projection instead of mercator projection, the streamlines are out of the border. This makes me so confused.
% Example in high-latitude Arctic and use the lambert projection
% Define a grid of latitude and longitude
lat = linspace(55, 67, 100); %
lon = linspace(174, 205, 100); %
[Lon, Lat] = meshgrid(lon, lat);
% Define synthetic vector field data (U, V)
% U and V represent the eastward and northward components of the velocity
U = cosd(Lat) .* sind(Lon); % Eastward component
V = sind(Lat) .* cosd(Lon); % Northward component
% Set up the map using m_map and the lambert projection!
m_proj('lambert', 'lat', [min(lat) max(lat)], 'lon', [min(lon) max(lon)]);
m_coast('patch', [0.7 0.7 0.7]); % Add coastlines with a gray patch
m_grid('box', 'fancy', 'tickdir', 'in'); % Add a grid with fancy box style
% Convert lat/lon to map coordinates
[X, Y] = m_ll2xy(Lon, Lat);
% Plot streamlines using streamslice
hold on;
h = streamslice(X, Y, U, V); % Plot streamlines
set(h, 'Color', 'r'); % Set streamline color to red
% Add additional plot elements if needed
title('Streamlines in high-latitude');
In this figure you can see the streamlines are out of the border after lambert projection, it seems that the data doesn't convert from lat/lon to map coordinates.
Could you please help me further? Thank you so much!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Weather and Atmospheric Science 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by