Overlaying two contour plots on same axis

조회 수: 127 (최근 30일)
James Wyatt
James Wyatt 2020년 3월 30일
댓글: Elie Hatem 2020년 8월 31일
I am trying to plots two contours on top of each other
Code is below, cannot work out why it is not working.
figure(1)
[c1,h1]=contourf(long1,lat1,squeeze(asal(:,:,36))',[34.6:0.01:34.9],'LineColor','none')
cmocean('balance')
colorbar
hold on
[c2,h2]=contour(long1,lat1,squeeze(pot_dens(:,:,36))',[26.80:.01:27.0],'k--')
clabel(c2,h2)
I have attached the different plots seperately, and the combined result.
I want just the sal plot as is, with the potential density contours overlaid
Thanks in advance
  댓글 수: 3
James Wyatt
James Wyatt 2020년 6월 22일
편집: darova 2020년 6월 22일
Hi Elie,
I have some code that works kind of well:
figure(1)
ax(1)=axes;
contourf(long1,lat1,squeeze(PV(:,:,34))',[0.05*10^-10:0.05*10^-10:1*10^-10],'LineColor','none')
cmocean('balance')
hc(1)=colorbar;
ax(2)=axes;
[c2,h2]=contour(long1,lat1,squeeze(dyn_height(:,:,34))',[10:.1:15],'c--')
clabel(c2,h2)
set(ax(2), 'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
pos=get(ax(1),'Position');
set(ax,'Position',[pos(1) pos(2) 0.9*pos(3) pos(4)]);
cpos=get(hc(1),'position');
set(hc(1),'position',[cpos(1)+0.05 cpos(2:4)]);
title('PV at 500m depth in SEI Ocean with dynamic height overlay')
xlabel('Longitude')
ylabel('latitude')
This does give an overlay, however I'm sure there is probably a simpler way of doing it.
Elie Hatem
Elie Hatem 2020년 8월 31일
Thank you !

댓글을 달려면 로그인하십시오.

답변 (1개)

Pratheek Punchathody
Pratheek Punchathody 2020년 8월 31일
Hi James,
As per my understanding you are looking for plotting two contour plots on the same axis.
Here is the reference code where two contour plots are overlaid on the same axis.
%%code starts here
Z1 = peaks; %Sample data 1
Z2 = peaks.^2; %Sample data 2
hold on
contourf(Z1,'-r');
contour(Z2,'--k');
colormap('map')
axis equal
%%code ends here
The plot for the above code with the sample data where the two counter plots are overlaid is shown below
The output figure shows both Z1 and Z2 are contour plotted on the same axis, with Z1 being filled 2D plot and Z2 with the contour plot.
Potential density contours are overlaid with the different colour using the "colormap"
Contour plots can be colour mapped using the “colormap”. For more information on colour mapping the contour plots, please check here
Look for the alternate solutions in this link where two contours can be overlaid in a subplot.
Reference information on Filled 2D contour Plot the Contor plot

카테고리

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