How can i use transparency parametr in plot3 or other method to make my plot semi transparency

I want to make my plot3 semi transparency
l1=20;l2=50;l3=40;
t1=linspace(-180,180,45)*pi/180;
t2=linspace(-180,180,45)*pi/180;
t3=linspace(-180,180,45)*pi/180;
[T1,T2,T3]=ndgrid(t1,t2,t3);
xM = round(l2*cos(T1).*cos(T2)+l3*cos(T1).*cos(T2+T3));
yM = round(l2*sin(T1).*cos(T2)+l3*sin(T1).*cos(T2+T3));
zM = round(l1+l2*sin(T2)+l3*sin(T2+T3));
w=plot3(xM(:),yM(:),zM(:),'b.','LineWidth',0.3)
i have try
w.color(4)=0.5
and changing Alpha paremetr but it didnt work
Thanks for your help

Answers (1)

You can play around with some hidden marker properties.
%get marker handles
markers=w.MarkerHandle;
%change transparency by altering 4th element
markers.EdgeColorData=uint8([0 0 255 50])'
edit: You have to add drawnow before those two lines of code
Read more here ( link ).

11 Comments

w.color(4)=0.5 is exacly marker and its not working (2014 and newer version of matlab create marker by .)
What do you mean not working? Is the attached result not what you are looking for?
Can you give me all code to generate what u have shown in this png ?
For some reason it only works for me if I write those two lines of code in the command window after I execute your script. Dont ask my why that is the case...
Use alpha of 20-30 to get the same result as the previous attachment.
Its puzzle taht it doesnt work in script but work in comand window. How would you use it with alpha on script ?
Dont know. Maybe someome smarter than me can chime in.
No problem. Maybe these will help you
https://se.mathworks.com/matlabcentral/answers/249044-code-fails-to-run-in-function-works-in-command-window-works-in-debug-evaluate-selection
https://se.mathworks.com/matlabcentral/answers/90391-the-command-is-working-perfectly-in-the-command-window-but-not-as-a-script
I found out one more think. When you zoom in or out it disables transparency effect.
btw, I have updated the answer to fix the previous issue with command not working in script.
I don't have a fix for your most recent issue. If you want to pan/rotate, the transparancy is reset and you must manually update it. If you want to print a specific view, just change the view() in the script before changing the transparency.
Ye zooming in / out and then copy paste last line fix it 2

Sign in to comment.

Tags

Asked:

on 28 Jun 2018

Commented:

on 29 Jun 2018

Community Treasure Hunt

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

Start Hunting!