How can overlay two contour plot in a subplot?

37 views (last 30 days)
Hello,
I am trying to plot and overlay two contour plots in the same figure but with some specifications. Both plots share the same x and y coordinates (and scales).
1. This two contour plot must be in a subplot of 2x1.
subplot(2,1,1)
2. The first contour plot (background) must be with lines and filled with his own colorbar.
Z1 = peaks;
contourf(Z1,'--')
colorbar
axis equal
3. The second contour plot (foreground) must overlay the first one and NOT be filled, just lines without colorbar.
Z2 = peaks.^2;
contour(Z2,'-')
axis equal
I am not using my real data for simplicity. How can we overlay this plots? Without destroying the first plot (preserve colors and colorbar). I reviewed these links but when I use the subplot function it does not work.
Thanks in advance for the answers.

Accepted Answer

Lemuel Carlos Ramos Arzola
I found this solution
Z1 = peaks;
Z2 = peaks.^2;
ax = subplot(2,1,1);
hold on
contourf(Z1,'--')
colorLim = ax.CLim;
contour(Z2,'-k')
ax.CLim = colorLim;
colorbar
axis equal
First, we saved the color limits CLim. Then, we plot the second contour plot and set the CLim from the previous one.

More Answers (0)

Categories

Find more on Contour Plots 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!