Contour lines above surf or mesh plot (plot viewed top down)
6 次查看(过去 30 天)
显示 更早的评论
Hi,
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;
clc;
data=importdata('depth averaged velocity 2010 referentie.mat');
[tt,m,n]=size(data.XComp);
T = input('Choose Timepoint T:');
zx=data.XComp(T,:,:); % picks flow velocity at t=T from flow velocity matrix
zy=data.YComp(T,:,:);
zx=reshape(zx,m,n); % zx isn't plotted in this script
zy=reshape(zy,m,n);
hold on
surf(data.X,data.Y,zy,'FaceAlpha',0.5);
view(2);
shading flat
colormap(flipud(colormap));
[c,h]=contour(data.X,data.Y,zy,'k',);
clabel(c,h);
hold off
0 个评论
回答(1 个)
Babak
2012-12-12
You have a typo at this line:
[c,h]=contour(data.X,data.Y,zy,'k',);
Change it to
[c,h]=contour(data.X,data.Y,zy,'k');
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
...
[c,h]=contour(data.X,data.Y,zy,'k',);
colormap(flipud(colormap));
...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!