MATLAB Answers

How to limit the contour plot with a line plot?

18 ビュー (過去 30 日間)
Philippe Corner
Philippe Corner 2018 年 11 月 1 日
コメント済み: Star Strider 2018 年 11 月 2 日
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 件のコメント

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2018 年 11 月 1 日
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 件のコメント

表示 1 件の古いコメント
Star Strider
Star Strider 2018 年 11 月 1 日
As always, my pleasure!
I looked at your other post earlier. It would appear that the slice (link) function might be most appropriate, except that your data are not volumetric.
Other than that, I do not know what to suggest.
Philippe Corner
Philippe Corner 2018 年 11 月 2 日
Thanks Strider, Someone advised me this: convert your images in a 3D stack filled with NaN otherwise and use slice. What do you think about that?
Star Strider
Star Strider 2018 年 11 月 2 日
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.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by