How can I make my scatter plot markers opaque, or semi transparent?

조회 수: 3 (최근 30일)
Janice
Janice 2014년 3월 13일
답변: Mathieu NOE 2025년 2월 7일
I am only 2 weeks old in computer programming so please bare with me my background is neuroscience!
So I have come far enough in a script to create a scatter plot and overlay it onto an image. I have managed to have the colour as a function of z-scores (Z) and size as a function of variable durS - which is awesome. All I need to know now is how to make the markers semi transparent so that I can see the overlap of markers and the image underneath.
Here is my code so far:
X = alldatamat(:,2); %xcoor
Y = alldatamat(:,3); %ycoor
Z = (pupilz);
%colour as a function of z scores
durS = alldatamat(:,4); %size of marker as a function of duration
figure(1); imshow(imselect); % brings up selected image
hold on;
Z = remap(Z,0,255); %% this is a made up function to retain colours when superimposed on image
ps = scatter(X,Y,durS,Z,'filled');
please help me make markers semi transparent (I tried alpha and played around with a few other things), or maybe suggest another way I can do this. In your answer please assume I know the least! Thanks!
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2025년 2월 7일
hello
can you share the data and image as well ? (use the paperclip button)

댓글을 달려면 로그인하십시오.

답변 (1개)

Mathieu NOE
Mathieu NOE 2025년 2월 7일
hello again
a small demo to see the effect of the scatter function parameter 'MarkerFaceAlpha' on the dots transparency
with 'MarkerFaceAlpha' = 1 : no transparency
with 'MarkerFaceAlpha' < 1 : it get's more transprent as you decrease the value of MarkerFaceAlpha
here with MarkerFaceAlpha = 0.5
% Load the data
Image = imread('cameraman.tif');
% Display the original image
imshow(Image);
hold on;
% add some scatter dots wit transparency management
Ndots = 50;
[m,n] = size(Image);
X = randi([round(0.1*n),round(0.8*n)],Ndots,1);
Y = randi([round(0.1*m),round(0.8*m)],Ndots,1);
Z = 256*rand(Ndots,1);
durS = 256*rand(Ndots,1);
ps = scatter(X,Y,durS,Z,'filled','MarkerFaceAlpha',1);
colorbar
hold off

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by