Figure export/print always has gray background with png/jpg

82 次查看(过去 30 天)
Whenever I export a figure in matlab to a png or jpg, the background is always gray. This is the case with using the 'print' and 'saveas' functions, as well as the fileexchange function export_fig. I have tried toggling the inverthardcopy and color figure settings to no avail.
This is very strange because it is a recent problem that seems to come out of nowhere. That is, i had no problems one day on my machine and the next day the same code could not switch the background color (white is what i want). In fact, exporting figures on my home computer works exactly as expected.
For example, the following code will save a figure with a gray background on my laptop but a white background on my home computer.
>> a = rand(100,2); >> plot(a); >> set(gcf,'inverthardcopy','off'); >> set(gcf,'color','w'); >> saveas(gcf,'test.png');
Similarly, if i set inverthardcopy to 'on' and dont change the background color, my home computer png will have a white background and my laptop will have a gray one.
I have noticed that the only way i can get the correct background color on a saved image is by setting inverthardcopy to 'off', manually changing the figure color, and saving as a .bmp file.
Any ideas on what setting may have been changed on my laptop to cause this?
Thanks,
Jacob

回答(4 个)

Jan
Jan 2013-1-7
Did you alter any default settings in startup.m? Compare this on bogth computers:
get(0, 'Default')
In addition there is a field in the preferences dialog:
Preferences->Figure Copy Template->Copy Options->
* Use figure color
* Force white background
* Transparent background
Do you have the same setting on both computers?

Chris
Chris 2013-3-15
I had the same issue and removing the default figure color option did the job.
set(0,'DefaultFigureColor','remove')

Henry
Henry 2014-6-10
So I have had this problem when every figure i exported using the openGL renderer has a black background which i did not want. I searched through the internet for a solution but never came across an answer. I thought I would post on here in case anyone else comes across this thread.
It appears that a setting has been unwillingly changed (although I dont know which one). My solution was to find the preferences directory by typing prefdir into the command line.
prefdir
Close matlab
Delete this folder
Re-open matlab.
The folder is recreated but not previous settings or history is used by matlab. It is quite annoying but it solved the issue with always having the black background with exported figures
  3 个评论
jimmydx
jimmydx 2016-6-16
Thank you so much for this insight. I was able to solve my problem by deleting the prefdir. However, I only deleted the files that had been modified during the session where I started having problems. Of course it would be much more helpful to know 1) what triggered it and 2) what preference actually changed. Anyway, your solution saved me a huge headache.
Katherine
Katherine 2024-2-14
编辑:Katherine 2024-2-14
I have been searching for this solution for weeks! Your post may be 10 years old but it just saved me from yet another week of troubleshooting every code/manual formatting edit I can find!

请先登录,再进行评论。


Gaston
Gaston 2018-10-5
I had the same problem with saving a figure as a .eps file and none of the other answers solved my problem. What did work for me was replacing
saveas(gcf,'filename','eps');
by
print('filename','-depsc')

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by