How to use alphadata for markers in scatter plot so each marker has a different alpha value?

80 visualizaciones (últimos 30 días)
In the newest release of MATLAB marker transparency was implemented for scatter plots. However, as far as I can tell, one can only set a global alpha value that applies to ALL of the markers. I would like to have different alpha values for each marker, just like how one can assign different colors to each marker. How might I achieve this?
I envision something like:
SizeData = 10;
hS = scatter(X,Y,SizeData,ColorData,'filled',AlphaData);
I would like the result to be a scatter plot with the i-th marker located at [X(i),Y(i)] and colored by the value in ColorData(i), and having a transparency set by AlphaData(i). Any suggestions?
I have tried to achieve this using patch objects, since you can specify color and alpha data for each vertex, and try to just set the faces and edges to have no color. Unfortunately the FaceVertexCData and FaceVertexAlphaData don't seem to apply to the vertex Markers, all I can do is have it influence interpolated face color and face alpha, which is not what I'm going for.
  3 comentarios
Oliver Johnson
Oliver Johnson el 4 de Abr. de 2017
Currently, scatter does not accept an AlphaData argument, my syntax above was just to show what behavior I would like to obtain. Scattergroup objects have a MarkerFaceAlpha property, but it can only be set to a scalar, which applies to all of the markers. I want to set the transparency for each marker separately.
yeungor
yeungor el 6 de Nov. de 2017
This solution does not have the intersection behavior of alpha, but a solution that worked for me was to use HSV coloring as a fade out instead of transparency.
I was showing a trail of datapoints in time and wished them to fade out after a certain amount of elements - I used an hsv colormap where datapoints fading out had a saturation near 0 and recently added datapoints had a value of 1.
numtrail = 10;
t = linspace(0,2*pi);
xdata = cos(t);
ydata = sin(t);
hsvcmap = [0.6*ones(numtrail,1), linspace(1,0,numtrail)', ones(numtrail,1)];
figure(1),clf
ax = scatter(xdata(1:numtrail), ydata(1:numtrail), [], hsv2rgb(hsvcmap), 'filled');
axis([-1 1 -1 1])
for frame = (numtrail+1):length(xdata)
ax.XData = [xdata(frame) ax.XData(1:end-1)];
ax.YData = [ydata(frame) ax.YData(1:end-1)];
drawnow
end
However, I understand this might not work in your application.

Iniciar sesión para comentar.

Respuestas (1)

Prannay Jain
Prannay Jain el 7 de Abr. de 2017
I work for MathWorks and I have provided this feedback to the developers.
As a work around, you can set the alpha for every plot of the marker iteratively:
ax = axes;
hold on;
for i = 1:10
s = scatter(10*rand(1),10*rand(1),36,rand(1,3),'filled');
s.MarkerFaceAlpha = rand(1); %%marking every maker with different alpha value
end
  3 comentarios
yeungor
yeungor el 6 de Nov. de 2017
@Walter Roberson Do you mind if I ask what you mean? Because to me, it looks like that is what they are doing. (I'm assuming random won't repeat values within 10 calls, which isn't correct, but it seems unlikely)
Walter Roberson
Walter Roberson el 6 de Nov. de 2017
The original question had AlphaData(i) -- alpha values the user had somehow computed. If there is a moderate possibility of different locations having the same alpha value, then then it is more efficient to combine those into a single scatter call. The answer from Prannay Jain calls for using a separate scatter() for every point -- at which point one would wonder whether it would be more efficient to line() each point into existence separately than to scatter() each point into existence separately.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by