필터 지우기
필터 지우기

transparency issue using "plot" function

조회 수: 8 (최근 30일)
Yu Li
Yu Li 2023년 4월 10일
댓글: Walter Roberson 2023년 4월 10일
Hi:
I have two set of data, using the same function "plot", and implement 0.1 transparency, however, they looks very different, for the dataset 2, the transparency looks not as clear as the dataset 1, particular between time period from 9:30 am to 11:00 am, even though it has a less data density.
is there any reason leading this issue? below is the code to reproduce this issue:
figure('color','w')
plotObj1=plot(data1.time,data1.data,'color','b','LineStyle','-','LineWidth',1);
plotObj1.Color(4)=0.1;
title('data 1, transparency looks ok')
figure('color','w')
plotObj2=plot(data2.time,data2.data,'color','b','LineStyle','-','LineWidth',1);
plotObj2.Color(4)=0.1;
title('data 2, transparency looks bad')
Thanks!
Yu

답변 (1개)

Adam Danz
Adam Danz 2023년 4월 10일
Applying transparency to line objects is not documented and leads to issues in some circumstances (e.g. live scripts and loading saved fig files). The recommended workaround is to use a patch object.
In this solution, an anonyous wrapper converts the plot(x,y) values to patch(x,y,...). Due to the non-uniform density of the line, some parts will appear darker than others.
load data1
load data2
lineAlphaFcn = @(x,y,color,alpha) patch([x(:);NaT(1,'TimeZone',x.TimeZone)],[y(:);NaN],'r','EdgeColor','b','EdgeAlpha',0.08, 'LineWidth',1,'FaceColor','none');
figure()
plotObj1=lineAlphaFcn(data1.time,data1.data);
title('data 1, transparency looks ok')
figure()
plotObj2=lineAlphaFcn(data2.time,data2.data);
title('data 2, transparency looks bad')
  댓글 수: 3
Adam Danz
Adam Danz 2023년 4월 10일
The transparency of the edges is working as expected. If many objects with the same transparency overlap, the section of overlap will naturally be darker. Look at the line in the second figure around 12:00 where the density is lowest. The line is quite faded from standard blue due to the EdgeAlpha.
You can decrease the EdgeAlpha value but at some point the line will be difficult to see in the sections with low density.
Walter Roberson
Walter Roberson 2023년 4월 10일
The whole point of transparency is to blend together the new graphic with whatever graphic is "underneath" it. If you have a lot of lines in one place, then it is like putting a bunch of layers of colored tape: the more layers you put in, the less light gets through.
If what you want is a light color even in places where there is high density, then you should not be using transparency for that: instead you should just be using a non-transparent line of a lighter color.

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

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by