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

조회 수: 82 (최근 30일)
Jacob
Jacob 2013년 1월 7일
편집: Katherine 2024년 2월 14일
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')
  댓글 수: 2
Karl
Karl 2013년 4월 3일
Worked for me: with one change:
set(0,'DefaultFigureColor',[1 1 1])
Juan Martin Farias
Juan Martin Farias 2023년 1월 18일
Thanks Karl. Your answer sovled my problems.
Best

댓글을 달려면 로그인하십시오.


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