Why is the patch function modifying the line width of existing lines?

Hello all, I am having some trouble with the patch function, whenever I use it it is changing the line width (at least apparently) of already existing lines. Here is a code example:
t=0:0.01:4
figure
plot(t,t.^2)
hold on
plot([1,1],[0,16],'--r','LineWidth',2)
plot([2,2],[0,16],'--r','LineWidth',2)
plot([3,3],[0,16],'--r','LineWidth',2)
patch([1,1,2,2],[0,16,16,0],'b','FaceAlpha',0.1,'LineStyle','none')
Before the patch command, the lines have a specific width, but after it they change! Has someone faced this problem before? Is there any solucion to it?
Thank you very much in advance,
Ana

 採用された回答

Walter Roberson
Walter Roberson 2015 年 6 月 9 日

0 投票

When you add the patch() the renderer changes to OpenGL, as only OpenGL can handle transparency (FaceAlpha).

6 件のコメント

Ana
Ana 2015 年 6 月 9 日
OK! Thank you!
So it is a "problem" related to the transparency.
The solution I have adopted is to change the order of plotting, so the patch object is the first one and select a light color for it. Then I can do the rest of the plots on top of it and I don't need the transparency. My only issue now is that I am doing several patches on the same figure and I would like the intersections to have the "combinated" color. With this approach I guess I would have to do this manually, right?
Thanks for the quick reply!
Mike Garrity
Mike Garrity 2015 年 6 月 9 日
What version of MATLAB are you using?
Starting in R2014b, the painters renderer does handle transparency. Also starting in that version, the wide line support of the opengl renderer was improved. So you shouldn't hit these types of issues.
Ana
Ana 2015 年 6 月 9 日
The version I am using is R2013b. I have checked and the renderer after executing the patch line is OpenGL. I guess there is no solution in this version.
Tong Zhao
Tong Zhao 2022 年 7 月 29 日
Can you patch a shape with a custom edge line width?
Bruno Luong
Bruno Luong 2022 年 7 月 29 日
patch(..., 'LineWidth',2)
Tong Zhao
Tong Zhao 2022 年 7 月 29 日
@Bruno Luong thank you! It worked.

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

その他の回答 (0 件)

カテゴリ

質問済み:

Ana
2015 年 6 月 9 日

コメント済み:

2022 年 7 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by