Overlaying two contour plots on same axis

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

请先登录,再进行评论。

回答(1 个)

Pratheek Punchathody
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