Transparency (MarkerFaceAlpha) in scatter not working

I have the following lines in my code. I'm trying to make certain points transparent, but whatever I do and even when lowering "tr" to 0.00001, the points just do not get transparent. I've also tried it with the t.MarkerFaceAlpha in the code, also does not help. Why does the transparency not work? Is there another way to make it work?
batch = 100;
batcho = 0:batch-1;
for i=1:c_max;
color = cm(i,:)
x = cl{i}(:,1);
y = cl{i}(:,2);
size = (cl{i}(:,3).^1)*2;
tr = (cl{i}(:,3).^5)*1;
for j = 1 : batch : size(cl{i}(:,1),1) - batch + 1
t = scatter(x(j+batcho), y(j+batcho), size(j+batcho), 'MarkerFaceAlpha', tr(j), 'MarkerEdgeColor',color);
t.MarkerFaceAlpha = tr(j)
end
t = scatter(x(j+batch:end), y(j+batch:end), size(j+batch:end),'MarkerFaceAlpha', tr(j), 'MarkerEdgeColor',color);
t.MarkerFaceAlpha = tr(j)
end
I'm using batch in my code because I have 250k points to plot. cl contains different groups that add up to 250k data points

8 Comments

I'm not sure what you are aiming to do here. You create a lot of scatter plots that just all keep replacing each other and only the final one will remain at the end of this code. You would need a
hold on
instruction (or preferably giving it an axes handle) to keep all of your scatter plots.
Yes, sorry about that. There is a hold on line, but I am also adding more things to the plot, like lables and different axis., that's why I didn't include it here.
I've tried using the size as a replacement for the transparency, but that also doesn't get me what I need. For example, the size are values between 0-1, and taking the exponential of the size, e.g. size^2, will just make the values with a low size disappear. That does not look nice on the final plot, where it looks like as if some areas are just empty
I have been reading a lot of other questions related to this topic and no clear solution. Is it safe to assume that it is not possible yet?
h = scatter(rand(50,1), rand(50,1), 'g', 'filled', 'MarkerFaceAlpha', 0.3)
is working for me in R2019a on Mac.
The transparency of every singlle data points is different. Your suggestion does not apply a different transparancy to every single data point.
Within a single scatter plot object all points must have the same transparency. This appears to be what your original code is doing too since you are using a new call to scatter every time round your for loop where your alpha value changes.
I've also tried it without using the batches, i.e.
for i=1:c_max;
color = cm(i,:)
x = cl{i}(:,1);
y = cl{i}(:,2);
size = (cl{i}(:,3).^1)*2;
tr = (cl{i}(:,3).^5)*1;
for j = 1 : size(x,1)
t = scatter(x(j), y(j), size(j), 'MarkerEdgeColor',color);
t.MarkerFaceAlpha = tr(j)
end
end
But this takes too long to run for 250k data points. Is there a faster way of making every single data point get a different transparency?

Sign in to comment.

Answers (0)

Asked:

on 22 May 2019

Edited:

on 23 May 2019

Community Treasure Hunt

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

Start Hunting!