Transparency in scatter plot

70 visualizaciones (últimos 30 días)
Felipe Dicker
Felipe Dicker el 1 de Mzo. de 2024
Comentada: Star Strider el 26 de Sept. de 2025 a las 20:33
Say I have two vectors A and B and would like to have a scatter plot of them, however the transparency of each marker must vary according to corresponding values in a third vector C. The transparency for the smallest value of C should be 50% and for the largest value of C should be fully opaque.
Everything I've tried has rendered all points fully transparent as if they are not being plotted at all. Thanks in advance.

Respuestas (2)

Walter Roberson
Walter Roberson el 1 de Mzo. de 2024
scatter(VectorOfX, VectorOfY, VectorOfPointSizes, VectorOfColor, ...
'MarkerFaceColor', 'flat', 'MarkerEdgeColor', 'flat', ...
'AlphaData', VectorOfAlpha)
  1 comentario
Felipe Dicker
Felipe Dicker el 1 de Mzo. de 2024
Editada: Felipe Dicker el 1 de Mzo. de 2024
This yields them fully opaque. So far I have
ax1 = nexttile(t_lay);scatter(ax1,RPM(torque>0&power>0),torque(torque>0&power>0),15,'MarkerEdgeColor',[83 40 191]/255/2,'MarkerFaceColor',...
[83 40 191]/255,'LineWidth',1.0,"AlphaData",TPS/100);xlabel(ax1,"RPM");ylabel(ax1,"Wheel Torque (Nm)");

Iniciar sesión para comentar.


Star Strider
Star Strider el 1 de Mzo. de 2024
Editada: Star Strider el 1 de Mzo. de 2024
It would help to have representative data. I suspect the vector you are using as ‘C’ has very low positive values (perhaps on the order of 0.1 to 0.3 or something similar).
The documentation stares that the transparency vector has to be scaled to be between 0 and 1. This uses the rescale function to accomplish that, creating ‘Cr’ (‘C’ rescaled).
Try this —
N = 50;
A = randn(N,1);
B = randn(N,1);
C = randn(N,1);
Cr = rescale(C,0.5,1); % Scale To Correspond To 'MarkerFaceAlpha' Rnage of (0.5,1)
figure
hs = scatter(A, B, 200, C, 'p', 'filled');
s.AlphaData = Cr;
s.MArkerFaceAlpha = 'flat';
s.MarkerEdgeAlpha = 'flat';
colormap(turbo)
colorbar
Note that ‘C’ works normally to colour the markers, and ‘Cr’ varies their transparency within the allotted range.
EDIT — Corrected typographical errors.
.
  3 comentarios
Frank Gibbons
Frank Gibbons el 26 de Sept. de 2025 a las 19:24
That's what I see - no obvious alpha here: none of the overlapping stars shows anything "underneath" it, not even the teal ones, which are middle of the scale.
Star Strider
Star Strider el 26 de Sept. de 2025 a las 20:33
There were typographical errors in my earlier code that I just now caught.
The blue stars should be most transparent, and the red stars should be most opaque. In my corrected code, that is now apparent, especially the two stars at (-1.5,1.5) and the cluster near (-0.4,0.7).
Try this --
N = 100;
A = randn(N,1);
B = randn(N,1);
C = randn(N,1);
Cr = rescale(C,0.0,1); % Scale To Correspond To 'MarkerFaceAlpha' Rnage of (0.5,1)
figure
hs = scatter(A, B, 500, C, 'p', 'filled');
hs.AlphaData = Cr;
hs.MarkerFaceAlpha = 'flat';
hs.MarkerEdgeAlpha = 'flat';
colormap(turbo)
colorbar
.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by