Clear Filters
Clear Filters

how to plot 4D figure to describe changing in ocean ?

9 views (last 30 days)
Amal MM
Amal MM on 29 Sep 2024
Commented: Umar on 10 Oct 2024 at 14:30
Hi,
I have the oceanographic data ( Longitude , Latitude , Density ,Depth)
I want to plot the change of density with depth such as the picture
I try to plot with surf but give me the surface changing
Also I try slice but did’t work because my data is 2D
Longitude =300*400,
Latitude =300*400 ,
Density =300*400,
Depth =300*400

Answers (2)

Voss
Voss on 29 Sep 2024

"I try to plot with surf but give me the surface changing"

How did you use surf, and what was wrong with the result?

Have you tried the following?

surf(Longitude,Latitude,Depth,Density)

Umar
Umar on 30 Sep 2024

Hi @Amal MM ,

After reading through your comments, it seems that your task involves visualizing oceanographic data, specifically the relationship between density and depth across a grid defined by longitude and latitude. The data is structured in a 2D format, but your goal is to create a plot that effectively represents the changes in density with depth. Now, the challenge arises from the need to represent this data in a way that is both informative and visually appealing, while also addressing the limitations of the surf and slice functions in MATLAB.

So, to visualize the oceanographic data effectively, you can utilize MATLAB's scatter3 function to create a 3D scatter plot, where you a represent density as color and depth as the z-axis. This approach will allows you to convey the fourth dimension (density) through color coding, while maintaining a clear representation of the spatial dimensions (longitude and latitude) and depth. Since you mentioned that your data is structured as 300x400 matrices for longitude, latitude, density, and depth, we will create synthetic data for demonstration purposes. Convert the 2D matrices into vectors to facilitate plotting. Use scatter3 to plot the data, where the x-axis represents longitude, the y-axis represents latitude, the z-axis represents depth, and the color represents density. Add labels, a color bar, and a title to make the plot more informative. Here is a complete MATLAB code snippet that implements the above steps:

_% Generate Sample Data_
longitude = linspace(-180, 180, 400); % Longitude from -180 to 180
latitude = linspace(-90, 90, 300);    % Latitude from -90 to 90
[lon, lat] = meshgrid(longitude, latitude); % Create a grid of longitude and   
latitude
_% Create synthetic depth and density data_
depth = rand(size(lon)) * 5000; % Depth values between 0 and 5000 meters
density = 1025 + (depth / 5000) * 5; % Density values, increasing with depth
_% Reshape the Data_
lon_vector = lon(:);
lat_vector = lat(:);
depth_vector = depth(:);
density_vector = density(:);
_% Create the 3D Scatter Plot_
figure;
scatter3(lon_vector, lat_vector, depth_vector, 36, density_vector, 'filled');
view(3); % Set the view to 3D
grid on;

For more information on scatter3 function, please refer to

https://www.mathworks.com/help/matlab/ref/scatter3.html

_% Enhance Visualization_
xlabel('Longitude (degrees)');
ylabel('Latitude (degrees)');
zlabel('Depth (meters)');
title('Density Variation with Depth in Oceanographic Data');
colorbar; % Add a color bar to indicate density values
colormap(jet); % Use a colormap for better visualization

For more information on colormap(jet) function, please refer to

https://www.mathworks.com/help/matlab/ref/jet.html?s_tid=doc_ta

Please see attached.

Feel free to adjust the synthetic data generation to match your actual oceanographic data for more accurate visualizations.

Please let me know if you have any further questions.

  5 Comments
Umar
Umar on 10 Oct 2024 at 14:30
Hi @Amal MM,
Thank you for your response. I appreciate your acknowledgment. If there’s anything specific you would like to discuss further or if you have additional thoughts, please feel free to share.

Sign in to comment.

Categories

Find more on Oceanography and Hydrology in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!