How to Merge Color using "Area" Command?

조회 수: 7 (최근 30일)
Benjamin
Benjamin 2021년 4월 8일
답변: Star Strider 2021년 4월 8일
Hello
Dear experts,
I need to find a way around the fact that by using the area command in MATLAB, the new plotted color on top of the previous color. Is there any way that the colors merge?
Take a look at the figures below, please.
area([1 2 3],'FaceColor','red');hold on
area([.5 .6 .7],'FaceColor','blue');hold on
But I want the colors red and blue merge and turn into what ever color it will, for example purple in this case.
P.S. I already know that I can simply use the purple color in the example above, but because my actual MATLAB program are couple of curves, and I need to also see the color beneath the upper colors, that's why I tried to put an easy example here.
I appreciate your help in advance.
Regards.
  댓글 수: 1
Benjamin
Benjamin 2021년 4월 8일
편집: Benjamin 2021년 4월 8일
I also tried the patch and fill command, but they also result in covering the previous color!

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2021년 4월 8일
With respect to patch, set 'FaceAlpha'; of both to 0.5 (or anything less than 1) to see the two patches overlap, with appropriate colour mixing.
Example —
x = linspace(0, 3);
y1 = 1 + x/2;
y2 = 0.5 + x/5;
figure
patch([x, fliplr(x)], [y1, zeros(size(y1))], 'b', 'FaceAlpha', 0.8)
hold on
patch([x, fliplr(x)], [y2, zeros(size(y2))], 'r', 'FaceAlpha', 0.3)
hold off
Esperiment to get the result you want.

추가 답변 (1개)

Adam Danz
Adam Danz 2021년 4월 8일
You can use a patch object with interpolated face color.
This example in the documentation shows how to do this. Once you get it started, if you have any trouble, share what you've got, describe the new problem, and I can nudge you along in the right direction.

카테고리

Help CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by