MATLAB figure with transparent background into Google Slides

I am able to save a MATLAB figure with a transparent background, in EPS format. But Google Slides will not import an EPS file.
I can import other image formats (e.g. PNG) into Google Slides, but I don't seem to be able to create transparent-background PNGs in MATLAB.
I have searched this forum, and played around quite a bit with both exportgraphics and export_fig. I can't seem to get them to do what I want.
Any solution? (I have to use Google Slides.)

1 Comment

One way to do this is to place your transparent figure in a new PowerPoint slide. Save the PowerPoint and then go to your Google Slides presentation, go to File >> Import Slides and import your PowerPoint. The figure will be successfully transfered into Google Slides while maintaining its transparent background. (At least, it worked for me when I just tried it, although I saved my figure as an EMF file rather than an EPS).

Sign in to comment.

 Accepted Answer

This answer is an update to my previous comment with better instructions:
If all you need to do is create a MATLAB figure with a transparent background and then use it in Google Slides:
% Make your figure
x = linspace(0,2*pi,100);
y = cos(x);
figure
plot(x,y,'LineWidth',2,'Color','#f4320c')
When the figure is created, open the Property Inspector and change the background color to 'None':
Next, copy the figure by going to Edit >> Copy Figure:
You can then paste the figure into a PowerPoint slide and save the PowerPoint as normal. Then, go into Google Slides and navigate File >> Import Slides:
Then, you can import your PowerPoint as a Google Slide and it will transfer the MATLAB figure file while keeping its transparent background. You can then change the Google Slide background color to whatever you want to see that the figure is in fact transparent:

6 Comments

Thank you so much for the detailed instructions. I really appreciate it.
I have not tried to follow them yet, but ...
Perhaps I should have specified the desire to do all this programmatically. I do this for several figures, and I am often tinkering with them multiple times, even after putting them into Slides. Is there a way to avoid the manual steps?
Unfortunately, I do not know of any way that allows you to edit the contents of the figure after it has been put into a slide. However, while the following idea still requires the manual steps, it might improve the efficiency of the process: You can try to set up a workflow on your desktop computer that divides MATLAB, PowerPoint, and Google Slides into three sections of your screen. Then, complete three steps in the following order:
  1. Create your figure in the MATLAB section of your screen and keep the figure open for you to make changes using the Property Inspector tool as needed.
  2. Next, paste the figure into the PowerPoint section of your screen and save the PowerPoint.
  3. Finally, import the PowerPoint slide in the Google Sheets section of your screen.
If you wish to make further modifications to the figure, just simply return to the Property Inspector on the MATLAB section of your screen and repeat steps 1 through 3.
Example of the figure-->Google Slides workflow:
This might work even better if you have more than one monitor.
Thanks for spending so much time on this. To clarify, I really only meant making the MATLAB part programmatic, not the rest. Opening Property Inspector for every figure, every time I generate it, is a pain (and seems like it should not be necessary, even though I know it may be so).
An alternative to using the property inspector would be to write:
set(gca,'Color','none')
after creating your plot. Then, when the plot opens in the figure window the background color will already be transparent. At that point you can skip straight to Step 2 in my previous comment by selecting "Edit >> Copy Figure" from the figure window.
Unfortunately, you can't simply paste the figure into Google Slides because when you copy the figure it is saved to your clipboard in the EMF format, which Google Slides doesn't support. That's why I recommended my PowerPoint solution.
OK, I'll be trying all this out later, so it's all a bit theoretical in my head right now.
The thing I am hoping to be able to do is to (programatically) save the figure to file (as with exportgraphics or export_fig), after which I can import it into Google Slides (or into PowerPoint and then to Google Slides, if need be.)
I suspect, after all that you've said (plus my own exploration) that I'll be able to save to file (as EPS or EMF), import to PPT, then to Slides.
The following code worked for me.
rng default
f = figure;
plot(rand(7,1),rand(7,1))
set(f, "Color","none")
set(gca,"Color","none")
% Exporting the figure is irrelevant, since it has to be copied from the
% GUI (Edit --> Copy Figure) to be pasted into Excel
exportgraphics(f,"transparent figure.eps","BackgroundColor","none")
Then I had to use Copy Figure in the GUI, as you suggested, paste into Excel, and then import the slide into Google Slides.
A couple relevant comments:
  • EMF seems to be a Windows-specific format; MATLAB would not output that on my Mac.
  • I could save the EPS figure to file in the above code, but it seems that neither Google Slides nor Powerpoint will recognize it as a valid graphic file type, so I had to resort to using Copy Figure.
  • I am not sure that all of the colors I set to "none" are a required part of the solution, but it worked as coded there.
That second point is very frustrating! Obviously MATLAB is able to create the figure with an allowable format, but I can't figure out how to save it to file programatically in a way that will import into Excel.
Thanks again for all your effort here.

Sign in to comment.

More Answers (0)

Products

Release

R2023b

Community Treasure Hunt

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

Start Hunting!