How do you save a figure with a trasparent background?

조회 수: 862 (최근 30일)
Ron Beck
Ron Beck 2018년 3월 2일
댓글: Darcy Cordell 2023년 6월 21일
How do you save a figure with a trasparent background? I want to save a figure as a png image that has a transparent background so I can put the image into PowerPoint and the PowerPoint graphic will show through the Matlab figure.

답변 (3개)

jonas
jonas 2018년 3월 2일
편집: Stephen23 2018년 3월 14일
The most recent version of export_fig includes a -transparent option for .png export
  댓글 수: 4
Ron Beck
Ron Beck 2018년 3월 5일
Thanks for the response, but neither worked. Is it critical where I put the lines of code?
jonas
jonas 2018년 3월 14일
Sorry for the late response. If you did not solve it already perhaps you can upload the code and I will have a look.
The first option calls the current axis (gca), so it should be located after the figure. The other option should be at the beginning of the code.

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


cui,xingxing
cui,xingxing 2021년 8월 30일
since Matlab R2020a, use "exportgraphics", for example ,you can do like this
x = 0:.1:2*pi;
y = sin(x);
% save to transparented image
figure;
plot(x,y,'LineWidth',4);
set(gcf, 'color', 'none');
set(gca, 'color', 'none');
exportgraphics(gcf,'transparent.eps',... % since R2020a
'ContentType','vector',...
'BackgroundColor','none')
  댓글 수: 2
Niklas Kurz
Niklas Kurz 2022년 10월 10일
Awesome, thank you for providing this information!
Darcy Cordell
Darcy Cordell 2023년 6월 21일
Does this also work for png format? Doesn't seem to work for me...

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


Subba Reddy
Subba Reddy 2020년 1월 22일
Non matlab way, Can use gimp software to remove white background from image, by selecting the background with color select tool, invert selection and copy. Then create new gimp window with background option as tranperancy, and paste it into that and export that as png. Not programmable but can be used to prepare images for presentation.
  댓글 수: 2
James Van Zandt
James Van Zandt 2023년 5월 22일
is it no longer supported?
pdf
Warning: Background transparency is not supported; using white instead.
png
Warning: Background transparency is not supported; using white instead.
eps
Warning: Background transparency is not supported; using white instead.
>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.9.0.1467703 (R2020b)
James Van Zandt
James Van Zandt 2023년 5월 22일
Pardon - I was commenting on a previous suggestion. Here's the relevant code:
fprintf('pdf\n'); exportgraphics(gca,'l16.pdf','BackgroundColor','none');
fprintf('png\n'); exportgraphics(gca,'l16.png','BackgroundColor','none');
fprintf('eps\n'); exportgraphics(gca,'l16.eps','BackgroundColor','none');

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

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by