How to make plot colors transparent?

조회 수: 62 (최근 30일)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2020년 4월 29일
댓글: Walter Roberson 2020년 4월 29일
I need to make the color of this plot transparent as I am going to add some data points to it and I want the data points to be visible:
redcolor = [1, 0.8, 0.8];
bluecolor = [0.8, 0.8, 1];
h1 = plot3(xGrid(pos1,1), xGrid(pos1,2),xGrid(pos1,3),'s','color',bluecolor,'Markersize',5,'MarkerEdgeColor',redcolor,'MarkerFaceColor',redcolor);
hold on
h2 = plot3(xGrid(pos,1), xGrid(pos,2),xGrid(pos,3),'s','color',redcolor,'Markersize',5,'MarkerEdgeColor',bluecolor,'MarkerFaceColor',bluecolor);
I was wondering if it is possible in matlab?

채택된 답변

Walter Roberson
Walter Roberson 2020년 4월 29일
편집: Walter Roberson 2020년 4월 29일
? Are h1 and h2 how you are drawing what you show us? Your code shows you requesting 's' marker type: are your pos and pos1 big vectors and you are drawing lots and lots of separate points that together just look solid ??
Internally, Primitive Chart Line Objects, also known as line() objects, such as are generated by plot() or plot3(), do have provision for alpha data . However...
The hidden way to provide alpha data for line() objects is to provide a fourth coefficient on the colors, giving the alpha fraction. For example, redcolor = [1, 0.8, 0.8, 0.6]; for alpha 0.6. MATLAB will not complain when you do that. If you then ask it to display the Color property, it will only store the RGB components. However, if you ask to see h1.Edge.ColorData you will see a 4 x 1 uint8 array, the 4th component of which will be uint8(255 * the alpha you specified) .
But... that is for the lines, and the Edge property is only populated if a linestyle was specified. This does not have any effect on markers.
For MarkerEdgeColor and MarkerFaceColor, you cannot provide an alpha value at the time of the plot3() call. You can, though. work with h1.MarkerHandle.EdgeColorData and h1.MarkerHandle.FaceColorData . As described above, those are 4 x 1 uint8 matrices (unless 'none' was specified) provided that a marker was specified. You can change the properties to change the color of the markers. However, changing the 4th element of the quad does not appear to have any effect on what is drawn.
What can you do? Well, if you are not drawing lines, then use scatter(), which permits you to specify MarkerEdgeAlpha and MarkerFaceAlpha
  댓글 수: 2
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2020년 4월 29일
regarding your question "are your pos and pos1 big vectors and you are drawing lots and lots of separate points that together just look solid ??" Yes. They are lots of separate points that together look like solid.
Walter Roberson
Walter Roberson 2020년 4월 29일
Okay, in that case use scatter3()

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by