Search code examples
matlabcontour

overlaying isolines on contourf plot


I would like to be able to overlay isolines over a filled contour or surface as it is done in this figure: contour plot example

Can matlab overlay contour and contourf plots?

So far, I have tried this:


[X,Y] = meshgrid(x_cases,y_cases);
Points = length(x_cases)*length(y_cases);
resX = reshape(X,Points,1);
resY = reshape(Y,Points,1);
resZ = reshape(DataGrid_a,Points,1);

scatter(resX,resY,[],resZ,’filled’)
hold on 
contour(X,Y,DataGrid_b,'ShowText','on')

But I have to reduce the transparency of my scatter plot to be able to see the contour lines from DataGrid_b, it would be more ideal to not change the transparency and overlay my isolines. I appreciate any input you may give me! Thanks!


Solution

  • The simplest solution (and it's very hack) is to take advantage of the fact that 2D plots are plotted at Z = 0; So put your scatter points at some Z value below that.

    scatter3(resX,resY,-ones(size(resX)),[],resZ,’filled’)
    view(2)
    hold on 
    contour(X,Y,DataGrid_b,'ShowText','on')