How to limit the contour plot with a line plot?
3 views (last 30 days)
Show older comments
Philippe Corner
on 1 Nov 2018
Commented: Star Strider
on 2 Nov 2018
Im using this code to plot left side figure on attached image. Any suggestion to set the contour for not plotting upper a black line? Im looking for a result like the right side figure (edited on paint).
%plot2
%data
M2=[0.000000 1217.000000 594.503284
4.500000 1183.886353 2099.999905
9.000000 1220.000000 1071.599126
13.500000 1184.565430 2099.999905
18.000000 1219.000000 435.631812
22.500000 1185.150635 2099.999905
24.500000 1217.555542 320.541441
27.000000 1185.427490 2099.999905
31.500000 1216.000000 300.000012
36.000000 1185.981445 2099.999905
40.500000 1215.000000 306.778669
45.000000 1186.629272 2099.999905
49.500000 1216.000000 300.000012
54.000000 1187.214478 2099.999905
58.500000 1215.000000 300.000012
63.000000 1187.893555 2099.999905
67.500000 1218.000000 335.902870
72.000000 1188.572510 2099.999905
76.500000 1220.000000 359.615386
81.000000 1189.282715 2099.999905
85.500000 1224.000000 1382.480264
90.000000 1189.992920 2099.999905
94.500000 1225.000000 1206.023455
99.000000 1190.578125 2099.999905];
%upper limit
h2=[0.0 1217
4.5 1217
9.0 1220
13.5 1219
18.0 1219
22.5 1218
27.0 1217
31.5 1216
36.0 1215
40.5 1215
45.0 1216
49.5 1216
54.0 1215
58.5 1215
63.0 1217
67.5 1218
72.0 1219
76.5 1220
81.0 1222
85.5 1224
90.0 1225
94.5 1225
99.0 1224
103.5 1225];
figure (1)
X2=M2(:,1);
Y2=M2(:,2);
Z2=M2(:,3);
[x2,y2]=meshgrid(linspace(min(X2),max(X2),100),linspace(min(Y2),max(Y2),100));
z2=griddata(X2,Y2,Z2,x2(:),y2(:),'cubic'); %cubic for smoother results
[c,h]=contourf(x2,y2,reshape(z2,100,100));
hold on
plot(h2(:,1),h2(:,2),'k','linewidth',4) %upper boundary
0 Comments
Accepted Answer
Star Strider
on 1 Nov 2018
There is likely no way to prevent it from plotting in that region. The next best thing is to use a patch object to plot a white (or whatever color you want) area over it:
[x2,y2]=meshgrid(linspace(min(X2),max(X2),100),linspace(min(Y2),max(Y2),100));
z2=griddata(X2,Y2,Z2,x2(:),y2(:),'cubic'); %cubic for smoother results
[c,h]=contourf(x2,y2,reshape(z2,100,100));
hold on
YL = ylim;
XL = xlim;
patch([XL, fliplr(h2(:,1)')], [[1 1]*YL(2), fliplr(h2(:,2)')], 'w')
plot(h2(:,1),h2(:,2),'k','linewidth',4) %upper boundary
hold off
4 Comments
Star Strider
on 2 Nov 2018
That could work. I have no idea what your data are, other than what you posted, so I can offer no specific recommendations. There are a number of functions liked to in and at the end of the slice documentation that could be helpful.
More Answers (0)
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!