问题
If I print a figure in MATLAB the background of the plot gets rendered black instead of white, like this:
(But in the figure window of MATLAB it is white as it is supposed to be)
This is the code similar to the one used to print the figure(but will run copy-paste):
figure;
set(0,'DefaultAxesFontSize',13)
set(0,'DefaultTextFontSize',13)
set(gcf, 'Renderer', 'painters');
y = 1:100;
plot(y)
xlabel('Some X', 'FontSize', 14)
ylabel('Some Y', 'FontSize', 14)
title('Example', 'FontSize', 15)
legend('some function')
print(gcf,'test1.pdf','-dpdf')
If I add the following line, however, it works (but there a slight grey background in the areas around the plot, of course)
set(gcf, 'color', [0.99 0.99 0.99])
My MATLAB version is R2013a (8.1.0.604)
edit:set(gcf, 'InvertHardCopy', 'off');
does not resolve the issue.
edit2:
The problem seams to be caused by the HG2-Update.
回答1:
I'm also using the HG2-Update hack for the sake of beauty. Returning to HG1 is no option for me. Well, I don't have any problems with it, except one: printing directly to .pdf. That's what you're trying to do also. This functionality is still totally screwed up.
The solution: Save with the plot with -dsvg
as vector graphic, open the file in Inkscape and save again as pdf with the Export area is drawing checkmark set.
I actually hoped to find a way to script this procedure, without success. So you have to do it manually or wait for the final release of HG2.
回答2:
The copy-paste code actually works fine on my version (R2013a as well), but to ensure the background color stays what it appears to be like after print, use this:
set(gcf, 'InvertHardCopy', 'off');
You can look at the example in the matlab docs here under Setting the Background Color.
Thus, to get a different background color for your plot, use:
set(gcf, 'color', 'blue');
set(gcf, 'InvertHardCopy', 'off');
print(gcf,'test1.pdf','-dpdf')
来源:https://stackoverflow.com/questions/25185260/rendering-with-painters-and-hg2-leads-to-black-background-of-plot-after-printing