Search code examples
matlabchartstransparencymatlab-figure

How to make pie charts with transparency on matlab?


I am currently having trouble while adding transparency to my pie charts. I can't set using FaceAlpha or EdgeAlpha and using alpha alone kind of rips the edges of the chart when compiling the eps file.

Any tips?

figure;
subplot(1,2,1)
h=pie3(P1,[0 0 0 1 1])
set(h,'EdgeColor','none','LineStyle','none')
hold on
colormap cool
hold on

subplot(1,2,2)
h=pie3([PF PG],[1 0 ],{'X1','X2'})
set(h,'EdgeColor','none')
colormap cool
%alpha(0.5)

print teste -depsc2 

Solution

  • The output of pie3 is an array of handles. Some are handles to surfaces, some are to patches, and others are for text. You need to select the sub-set of these handles that actually have EdgeAlpha and FaceAlpha properties. You can do this using findobj.

    h = pie3(rand(1,5), [0 0 0 1 1]);
    
    set(findobj(h, '-property', 'FaceAlpha'), 'FaceAlpha', 0.2);
    set(findobj(h, '-property', 'EdgeAlpha'), 'EdgeAlpha', 0);
    

    enter image description here

    When exporting to an EPS though, transparency is not supported. Also, since you have transparency in your figure, MATLAB will use the OpenGL renderer which causes EPS files to not be rendered as you expect. You could try to use export_fig to get a better result.