How to use scatter with transparent dots?

 Risposta accettata

Adam Danz
Adam Danz il 9 Ott 2018
Modificato: Adam Danz il 14 Giu 2022
MarkerFaceAlpha and MarkerEdgeAlpha are what you're looking for. Check out this example.
[from the link]
x = [5 10 11 13 18];
y1 = [40 80 150 80 50];
a1 = 100*[100 50 80 30 50];
scatter(x,y1,a1,'MarkerFaceColor','b','MarkerEdgeColor','b',...
'MarkerFaceAlpha',.2,'MarkerEdgeAlpha',.2)
axis([0 20 0 200])
x = [2 6 8 11 13];
y2 = [30 40 100 60 140];
a2 = 100*[30 50 30 80 80];
hold on
scatter(x,y2,a2,'MarkerFaceColor','r','MarkerEdgeColor','r',...
'MarkerFaceAlpha',.2,'MarkerEdgeAlpha',.2)
hold off

7 Commenti

I am trying this with v2020b and it simply doesn't work - no combination of parameters makes the markers transparent.
Goal:
1) Plot a group of points on a geoaxis with a 3rd dataset that varies in color: Working
2) Plot two additional groups of points with the areas covered in a lightly tinted "blob": Not working, blob is full intensity, not transparent
Code:
f1 = figure(1);
clf;
gx1 = geoaxes;
geobasemap satellite
hold on
std_scaled = paawDF.std_Alt/(max(paawDF.std_Alt)-min(paawDF.std_Alt));
h1 = scatter(gx1,paawDF.lat_dd,paawDF.lon_dd,20,std_scaled,"filled");
h2 = scatter(gx1,decBigData.Latitude(taFilter),decBigData.Longitude(taFilter),5,"filled", ...
"Marker", 'o', ...
"MarkerFaceColor", [0 1 0],"MarkerEdgeColor",'none', ...
"MarkerFaceAlpha", .3, "MarkerEdgeAlpha", .3);
% param
% set(h2.MarkerHandle, 'FaceColorType','truecoloralpha', 'FaceColorData',uint8([0;200;0; 50]));
% h2 = plot(gx1,decBigData.Latitude(taFilter),decBigData.Longitude(taFilter),'o','Color',[0 1 0 0.2]);
h3 = plot(gx1,decBigDataWheel.Latitude(taFilterWheel),decBigDataWheel.Longitude(taFilterWheel),'.r');
% h2.MarkerFaceAlpha = .2;
% h2.MarkerEdgeAlpha = .2;
% h3.MarkerFaceAlpha = .2;
% h3.MarkerEdgeAlpha = .2;
Obviously, I have not run all of these settings at the same time, those commented out are other things I have tried.
All comments are welcome!
@Craig Puetz ok what you tried did not work. (I can't try it because I don't have the Mapping Toolbox.) But does @Adam Danz's original code work for you?
Moving @Craig Puetz's answer here
----------------------------------------------------
I went back and ran the original code (took me a minute to remember what this was even about!).
@Adam Danz Your code works properly and produces exactly the image shown in this example. I don't know why similiar commands don't produce similiar results in my example with the Mapping toolbox.
@Craig Puetz, we can't run your code without having the data (ie, paawDF, ect). Have you tried using geoscatter and geoplot instead of scatter and plot?
markerfacealpha and markeredgealpha is not doing anything, Matlab 2021b. Anyone else?
Depends on the marker you use. If you use a dot '.', you will not see any result. With other markers, you will. I've done this on R2020a though, so please double-check with your rev. Good luck!
@Damon Bradley, thank you! Would have been confused for a long time without this post.

Accedi per commentare.

Più risposte (0)

Richiesto:

il 9 Ott 2018

Commentato:

il 29 Gen 2024

Community Treasure Hunt

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

Start Hunting!

Translated by