Plotting lines with patch and transparency

조회 수: 15 (최근 30일)
Benjamin Pehlivanlar
Benjamin Pehlivanlar 2023년 1월 30일
답변: Sarvesh Kale 2023년 3월 14일
Dear community,
I am trying to use the patch function in order to draw lines with a level of transparency (alpha), but it does not seem to work (apparently patch is faster than plot when we have too many lines)
I have followed the guidelines from a Youtube video, by changing the last row value into NaN:
cycle.P_CY01(end,:).Variables=NaN(1,2003); % 7200 x 2003 matrix
Whenever my alpha variable is below 1, the lines will not be plotted:
alpha=zeros(1,2001)+.9;
alpha(:,idx)=1; % idx is the indexes of the lines I want to be above the others
The color is defined as follows:
color=ones(7200,2001);
color(:,1)=0;
color(:,idx)=2;
I am using the patch function the following way to plot:
patch(CKAISYS, cycle.P_CY01(:,3:end).Variables,... % CKAISYS is 7200x2001, with last row being NaN
color,'EdgeColor','flat','EdgeAlpha','flat',...
'FaceVertexAlphaData',alpha',"HandleVisibility","off");
colormap([black; grey; orange]) % where black, grey, and orange are predefined RGB triplets
Only the lines with alpha=1 will be plotted, the ones with 0.9 value will not be plotted. I want the lines with alpha=1 to be above the ones being at 0.9.
Isn't there a simpler way to do it? If I could directly assign RGB+alpha triplet (so nx4 matrix), instead of relying on colormap, that would be great.
Optional:
  • I am looking for a way to add the proper legend entry for each of these colors
  • I would like to have the first column with thicker linewidth (2 instead of 1)
I have looked up this website but it didn't help me too much: Patch Properties (MATLAB Functions) (northwestern.edu)
Thank you
  댓글 수: 1
dpb
dpb 2023년 1월 30일
I think if you want anybody here to try to diagnose/debug this you'll need to attach a standalone demo code snippet that illustrates the issue you're having. We can't run your code and it's too much to expect somebody to try to make up something from scratch that would match what you're after.

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

답변 (1개)

Sarvesh Kale
Sarvesh Kale 2023년 3월 14일

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by