To overlay a contour plot with multiple lines, similar to the attached image, kindly refer to the steps mentioned below:
1. Use the "contour" function in MATLAB to plot the function "u(x,y,t)" as a function of "x" and "y" for a given value of "t". You can refer to the MATLAB code snippet below to do so:
% Plot contour
figure;
contour(x, y, u);
hold on;
Here, "x" and "y" are the coordinates at which the function "u(x,y,t)" is evaluated and stored in "u".
2. Use the "contour" function along with the "hold" function and "plot" function to overlay lines on the contour plot. The "hold on" command retains the plots in the current axes, ensuring that new plots do not delete existing ones. You can then add as many lines as required using the "plot" function. Below is a MATLAB code snippet for reference:
plot(x_line, y_vals, 'k', 'LineWidth', 2);
title('Contour Plot of u(x, y, t) with Overlaid Line');
xlabel('x');
ylabel('y');
axis equal;
grid on;
hold off;
You can add as many lines as needed by repeatedly using the "plot" function. Once all desired lines are added, use the "hold off" command to stop retaining the current axes for further plots.
The documentation links of "contour", "plot" and "hold" functions are mentioned below for your reference:
- contour: https://www.mathworks.com/help/releases/R2021b/matlab/ref/contour.html
- plot: https://www.mathworks.com/help/releases/R2021b/matlab/ref/plot.html
- hold: https://www.mathworks.com/help/releases/R2021b/matlab/ref/hold.html
Hope this helps!