How can overlay two contour plot in a subplot?

조회 수: 16 (최근 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
Lemuel Carlos Ramos Arzola 2020년 2월 9일
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에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by