I have a plot in Matlab and am setting the background to transparent by:
set(gcf, 'Color', 'None');
set(gca, 'Color', 'None');
When I try to save the image (from the viewer), I save as a ".png", but it saves with a white background. How can I save it with the transparent background?
You may be used to saving image files for web use as JPEGs, but JPEGs don't support transparent backgrounds. So, instead, you'll need to use a format such as GIF, TIF or, ideally, PNG. The PNG file is small enough for use online but still delivers high quality with transparency as well.
Simply click the “Download' dropdown menu, then check the box that says “Transparent background.” Ensure that you don't have a background image loaded on the canvas.
The JPEG format doesn't support transparency. But we can create our own transparency using a second image as an alpha channel.
It is disappointing but, MATLAB's default saveas
and print
commands cannot deal with transparent things very well. You'll have to save it with some background and then convert it either through imread
/imwrite
or some other tool.
There are some tools that might be helpful:
I prefer vector graphics, so use svg exports when transparency is needed. If indeed you have a bitmap, use imwrite(bitmapData, 'a.png', 'png', 'transparency', backgroundColor)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With