Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Contour lines above surf or mesh plot (plot viewed top down)

Asked by Wilbert on 11 Dec 2012


I want to plot an array in top down view and have contour lines (with labels) above the colormap. Now the colormap is placed over the contour lines for some values, because the contour plot is at z=0 and some values in the array larger than z=0. When I set FaceAlpha to 0.5 the contour lines are somewhat visible, but this isn't exactly an elegant solution.

Does somebody have a good solution?

This is the code I use:

clear all;
close all;
data=importdata('depth averaged velocity 2010 referentie.mat');
T = input('Choose Timepoint T:');
zx=data.XComp(T,:,:); % picks flow velocity at t=T from flow velocity matrix
zx=reshape(zx,m,n); % zx isn't plotted in this script
hold on
shading flat
hold off




No products are associated with this question.

1 Answer

Answer by Babak on 12 Dec 2012

You have a typo at this line:


Change it to


If you need better resolution for the contourmap, you need to use, meshgrid() for your data.X and data.Y and use finer grids! I mean if you are having

 data.X = linspace(-1,1,100);

Change it to

 data.X = linspace(-1,1,200);

which has more points and creates a finer mesh.

You would also want to swap these the two lines of contour and colormap, use


1 Comment

Wilbert on 12 Dec 2012

A point-for-point reply:

- I made that typo only here, it's not in my script.

- About the resolution of the contour line, the resolution is good enough. It's a fairly large grid of several km^2.

- I have swapped the two lines, is indeed more efficient.

But your answer doesn't solve my problem at all. The resolution of the grid isn't the problem. The problem is that the contour lines aren't always on top, but are under the colormap. I attached two plots to help visualizing the problem.

The last figure shows the problem, the contour lines are under the colormap. Changing the transparancy solves the problem a bit, but that's not the solution I am looking for.


Contact us