How to make plot colors transparent?

65 Ansichten (letzte 30 Tage)
Zeynab Mousavikhamene
Zeynab Mousavikhamene am 29 Apr. 2020
Kommentiert: Walter Roberson am 29 Apr. 2020
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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 29 Apr. 2020
Bearbeitet: Walter Roberson am 29 Apr. 2020
? 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 Kommentare
Zeynab Mousavikhamene
Zeynab Mousavikhamene am 29 Apr. 2020
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 am 29 Apr. 2020
Okay, in that case use scatter3()

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by