Overlaying two contour plots on same axis

135 visualizaciones (últimos 30 días)
James Wyatt
James Wyatt el 30 de Mzo. de 2020
Comentada: Elie Hatem el 31 de Ag. de 2020
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 comentarios
James Wyatt
James Wyatt el 22 de Jun. de 2020
Editada: darova el 22 de Jun. de 2020
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 el 31 de Ag. de 2020
Thank you !

Iniciar sesión para comentar.

Respuestas (1)

Pratheek Punchathody
Pratheek Punchathody el 31 de Ag. de 2020
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

Categorías

Más información sobre Contour Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by