How to make plot colors transparent?

60 次查看(过去 30 天)
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
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by