Overlaying two contour plots on same axis

126 ビュー (過去 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 Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by