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

82 visualizaciones (últimos 30 días)
Jacob
Jacob el 7 de En. de 2013
Editada: Katherine el 14 de Feb. de 2024
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

Respuestas (4)

Jan
Jan el 7 de En. de 2013
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 el 15 de Mzo. de 2013
I had the same issue and removing the default figure color option did the job.
set(0,'DefaultFigureColor','remove')
  2 comentarios
Karl
Karl el 3 de Abr. de 2013
Worked for me: with one change:
set(0,'DefaultFigureColor',[1 1 1])
Juan Martin Farias
Juan Martin Farias el 18 de En. de 2023
Thanks Karl. Your answer sovled my problems.
Best

Iniciar sesión para comentar.


Henry
Henry el 10 de Jun. de 2014
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 comentarios
jimmydx
jimmydx el 16 de Jun. de 2016
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 el 14 de Feb. de 2024
Editada: Katherine el 14 de Feb. de 2024
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!

Iniciar sesión para comentar.


Gaston
Gaston el 5 de Oct. de 2018
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')

Categorías

Más información sobre Entering Commands en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by