Line through polygon using patch

14 views (last 30 days)
ashley Raby on 22 Feb 2016
Commented: Angelica Laurita on 11 Jun 2021
I am trying to use a work-around in order to make a transparent line. It works, however, I keep getting a line through the middle of my graphic. Can somebody please tell me why?
x = linspace(0,10);
y1 = 4 + sin(x).*exp(0.1*x);
y2 = 4 + cos(x).*exp(0.1*x);
patch(x, y2, 'w', 'EdgeColor', 'r', 'EdgeAlpha', 1, 'FaceColor', 'r', 'FaceAlpha', 1)
hold on
patch(x, y1, 'w', 'Edgecolor', 'b', 'EdgeAlpha', 0.3, 'FaceColor', 'w', 'FaceAlpha', 0)
hold off
2 CommentsShow 1 older commentHide 1 older comment
ashley Raby on 24 Feb 2016
In the long term I want to create a transparent line. One of the first steps toward accomplishing this is to use the patch function to create filled polygons.
I want to re-create the picture below with the pink and the blue polygons. This image is included in Mathworks documentation. However it gives conflicting information so I can't re-create it the way they suggest. You can find it here http://www.mathworks.com/help/matlab/visualize/add-transparency-to-graphics-objects.html?searchHighlight=transparency. When I try to make it using "area", it tells me that "FaceAlpha" is not a property of "area". Therefore this is my attempt at creating this image using "patch" instead of "area" because I can use "FaceAlpha" when I use "patch".
The two lines that I want to get rid of I have highlighted yellow in the picture below.

Mike Garrity on 22 Feb 2016
Patch wants to draw closed polygons. If you don't want the line from the end of the second patch back to the beginning, then the easiest way is to add a nan like this:
x = linspace(0,10);
y1 = 4 + sin(x).*exp(0.1*x);
y2 = 4 + cos(x).*exp(0.1*x);
patch(x, y2, 'w', 'EdgeColor', 'r', 'EdgeAlpha', 1, 'FaceColor', 'r', 'FaceAlpha', 1)
hold on
patch([x nan], [y1 nan], 'w', 'Edgecolor', 'b', 'EdgeAlpha', 0.3, 'FaceColor', 'w', 'FaceAlpha', 0)
hold off
2 CommentsShow 1 older commentHide 1 older comment
Angelica Laurita on 11 Jun 2021
Hello! I'm having the same problem, but I cannot solve it using nan since I obtain the error "Error using horzcat. Dimensions of arrays being concatenated are not consistent."
Any ideas on how I could do?
Than you!