Transparency in scatter plot
24 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
Walter Roberson
2024-3-1
scatter(VectorOfX, VectorOfY, VectorOfPointSizes, VectorOfColor, ...
'MarkerFaceColor', 'flat', 'MarkerEdgeColor', 'flat', ...
'AlphaData', VectorOfAlpha)
Star Strider
2024-3-1
编辑:Star Strider
2024-3-1
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.
.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!