Reputation: 201
I am creating surface plots with a transparent figure background in Matlab R2015b. Consider the code
n=49;
h=figure;
[x,y]=meshgrid(1:n,1:n);
surf(x,y,peaks(n),'EdgeColor','none')
set(h,'Color','none')
set(h, 'InvertHardCopy', 'off');
print(h,'-dpdf','peaks.pdf')
which gives me a pdf file peaks.pdf
where the axes background is white, but the figure background transparent.
However, if I set n=1000
, the background is no longer transparent, but black (as the figure is displayed in Matlab).
Does anyone know, what the issue is, and how to prevent this? Thanks!
Upvotes: 1
Views: 3005
Reputation: 884
The key is the property set(h, 'InvertHardCopy', 'off');
From the MATLAB help:
InvertHardcopy — Figure background color when printing or saving
'on'(default) | 'off'
Figure background color when saving or printing, specified as one of these values:'on' — Change the figure background and axes background colors to white.
'off' — Use the same colors as the colors on the display. To change the figure background color on the display, use the Color property of the figure. To change the axes background color, use the Color property of the axes.
Accordingly, you should use set(h, 'InvertHardCopy', 'on');
to get the desired pdf output.
Upvotes: 1