How I can plot surface countour plot and velocity plot on same garph using MATLAB

1 visualizzazione (ultimi 30 giorni)
How I can plot surface countour plot and velocity plot on same garph using MATLAB

Risposte (1)

ag
ag il 30 Gen 2025
Hi Sharad,
This can be achieved by using the "hold" feature of MATLAB. The below code demonstrates how to do the same:
% Generate example data for the surface
[X, Y] = meshgrid(-2:0.1:2, -2:0.1:2);
Z = X .* exp(-X.^2 - Y.^2);
% Generate example data for the velocity field
[U, V] = gradient(Z);
% Create the contour plot
figure;
contourf(X, Y, Z, 20); % 20 specifies the number of contour levels
colormap(jet); % Select a colormap
colorbar; % Display the colorbar
hold on; % Retain current plots to add more
% Overlay the velocity field
quiver(X, Y, U, V, 'k'); % 'k' denotes black arrows
% Add labels and a title
xlabel('X-axis');
ylabel('Y-axis');
title('Surface Contour Plot with Velocity Field');
% Adjust axis limits if necessary
axis tight;
hold off;
For more details, please refer to the following MathWorks documentation: https://www.mathworks.com/help/matlab/ref/hold.html
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by