How to graph a patch that follows a line?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Philippe Corner
el 4 de Sept. de 2019
Comentada: Philippe Corner
el 5 de Sept. de 2019
I'm trying to export my figure without background using the attached code. As you may see, I'm using a patch function to cover a very small area, I want to use a smaller patch that follows the red line (see line 91). Any ideas about how to do it?
The idea is tha my patch does follow only YL = ylim, but it follows the same tendency of red line line, and with a small thikness, maybe 1 unit or something like that.
clear;clc
A=[ -12.236 1417.575 3.629 0.2756 6.495
-4.239 1416.849 1.700 0.5884 10.726
3.764 1415.702 8.779 0.1139 18.386
11.765 1414.657 19.057 0.0525 0.357
19.767 1413.565 23.490 0.0426 1.128
27.773 1412.141 6.767 0.1478 2.323
35.778 1410.820 6.459 0.1548 0.816
51.771 1409.493 13.318 0.0751 0.005
67.743 1409.605 2.851 0.3507 19.542
75.736 1409.051 4.407 0.2269 0.005
83.685 1409.926 3.746 0.2670 6.940
91.646 1410.386 6.075 0.1646 21.096
99.640 1409.575 8.106 0.1234 5.910
107.620 1409.047 7.330 0.1364 12.873
123.623 1407.111 19.248 0.0520 4.626
131.608 1406.459 19.462 0.0514 4.579
155.748 1398.703 10.460 0.0956 4.238
163.770 1396.466 10.020 0.0998 1.405
171.768 1395.721 9.112 0.1097 0.925
179.769 1394.702 10.088 0.0991 0.347
187.762 1394.345 38.594 0.0259 1.539
195.760 1393.510 33.104 0.0302 2.456
203.770 1391.803 22.253 0.0449 4.501
211.773 1390.669 18.235 0.0548 4.996
-4.714 1412.787 11.198 0.0893 11.495
3.294 1411.678 35.189 0.0284 19.953
11.297 1410.652 1.944 0.5143 9.786
19.302 1409.587 22.708 0.0440 2.563
35.329 1406.982 2.800 0.3571 51.108
43.336 1405.852 8.600 0.1163 1.075
51.311 1405.562 24.378 0.0410 3.769
59.264 1405.778 3.745 0.2670 0.405
67.242 1405.315 27.800 0.0360 23.019
75.225 1404.677 32.562 0.0307 0.161
91.021 1405.037 2.033 0.4919 33.104
106.966 1403.454 0.401 2.49 13.230
114.978 1402.459 0.414 2.42 13.897
130.941 1400.754 0.532 1.88 6.411
138.998 1399.510 3.936 0.2540 2.818
147.118 1397.609 6.552 0.1526 1.683
155.255 1394.488 43.711 0.0229 4.206
163.310 1392.528 36.826 0.0272 1.930
171.305 1391.754 25.253 0.0396 1.071
179.307 1390.750 9.461 0.1057 0.656
187.288 1390.294 7.927 0.1261 1.636
195.285 1389.441 26.961 0.0371 2.424
203.310 1387.864 27.695 0.0361 4.414
211.316 1386.764 15.058 0.0664 5.489];
X = A(:,1);
Y = A(:,2);
Z = A(:,3);
[xq,yq]=meshgrid(linspace(min(X),max(X),100),linspace(min(Y),max(Y),100));
zq=griddata(X,Y,Z,xq(:),yq(:),'cubic'); %cubic for smoother results
figure()
[c,h]=contourf(xq,yq,reshape(zq,100,100));
colormap(jet(5))
axis equal
hold on
cota=[ -12.236 1417.575 3.629 0.2756 6.495
-4.239 1416.849 1.700 0.5884 10.726
3.764 1415.702 8.779 0.1139 18.386
11.765 1414.657 19.057 0.0525 0.357
19.767 1413.565 23.490 0.0426 1.128
27.773 1412.141 6.767 0.1478 2.323
35.778 1410.820 6.459 0.1548 0.816
51.771 1409.493 13.318 0.0751 0.005
67.743 1409.605 2.851 0.3507 19.542
75.736 1409.051 4.407 0.2269 0.005
83.685 1409.926 3.746 0.2670 6.940
91.646 1410.386 6.075 0.1646 21.096
99.640 1409.575 8.106 0.1234 5.910
107.620 1409.047 7.330 0.1364 12.873
123.623 1407.111 19.248 0.0520 4.626
131.608 1406.459 19.462 0.0514 4.579
155.748 1398.703 10.460 0.0956 4.238
163.770 1396.466 10.020 0.0998 1.405
171.768 1395.721 9.112 0.1097 0.925
179.769 1394.702 10.088 0.0991 0.347
187.762 1394.345 38.594 0.0259 1.539
195.760 1393.510 33.104 0.0302 2.456
203.770 1391.803 22.253 0.0449 4.501
211.773 1390.669 18.235 0.0548 4.996];
plot(cota(:,1),cota(:,2),'r', 'linewidth',2)
YL = ylim;
XL = xlim;
patch([XL, fliplr(cota(:,1)')], [[1 1]*YL(2), fliplr(cota(:,2)')], 'w')
set(gca,'YTick',[])
set(gca,'XTick',[])
set(gca,'XColor', 'none','YColor','none')
set(gca,'color','none')
4 comentarios
Respuesta aceptada
darova
el 4 de Sept. de 2019
I found boundary points and moved them down a bit
zq(isnan(zq)) = 1000; % replace NaN with big number
ix = find(diff(zq(:)) > 500); % find border indexes
plot(xq(ix),yq(ix)-0.5,'*-r')
Here is what i get
3 comentarios
darova
el 4 de Sept. de 2019
Just concantenate data:
xc = [cota(:,1); flipud(xq(ix))];
yc = [cota(:,2); flipud(yq(ix))];
patch(xc,yc,'w')
Or you can just replace data with NaN in between those lines:
xc = [cota(:,1); flipud(xq(ix))];% just concantenate data
yc = [cota(:,2); flipud(yq(ix))];
in = inpolygon(xq(:),yq(:),xc,yc);
zq(in) = nan;
[c,h] = contourf(xq,yq,zq);
Más respuestas (0)
Ver también
Categorías
Más información sobre Polygons en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!