How can overlay two contour plot in a subplot?

38 次查看(过去 30 天)
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.

采纳的回答

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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by