altmany / export_fig

A MATLAB toolbox for exporting publication quality figures
BSD 3-Clause "New" or "Revised" License
1.28k stars 368 forks source link

Problems with transparency with PDF formats #337

Closed mnissov closed 3 years ago

mnissov commented 3 years ago

I'm having some troubles exporting a figure with opaque fills into pdf format

The code I am using is

temp = randn(1e3,1);

figure(1)
histogram(temp)
grid on

set(gca, 'color', 'none');
export_fig(1, 'temp.pdf', '-pdf', '-transparent')

and the warning reads Warning: export_fig currently supports transparent patches/areas only in PNG output. To export transparent patches/areas to PDF, use the print command: print(gcf, '-dpdf', 'temp.pdf');

Perhaps this is just a misunderstanding from my side.

export_fig version 3.14 and matlab version 2020b on linux

Note: the result of the above code is a pdf image with the background set to black.

altmany commented 3 years ago

Matlab's histogram function creates a histogram using semi-transparent patches (FaceAlpha=0.6) and these can only be exported to PDF via print(gcf,'-dpdf',...) as the warning message clearly states. If you want to use export_fig, set the histogram's FaceAlpha property to 1.