Save OR open figure with transparent background

Hello,
I need to save my pie charts without white background behind it (transparent), I was searched dozens of webpages and tried:
set(gcf, 'color', 'none');
% and
set(gca 'color', 'none');
But not works for me. I even used export_fig from FEX in this syntax:
export_fig (ax, ['filename' num2str(k) '.png']);
But I got this error:
Unrecognized function or variable 'using_hg2'.
Error in export_fig>parse_args (line 1391)
options.aa_factor = 1 + 2 * (~(using_hg2(fig) && isAA) |
(options.renderer == 3));
Error in export_fig (line 330)
[fig, options] = parse_args(nargout, fig, varargin{:});
Here is all my code,
clf
f = figure();
ax = axes();
p = pie(ax, ones(1,5));
t = p(2:2:end);
p = p(1:2:end);
delete(t)
s = {'CC', 'ME', 'NU', 'BI', 'IA'};
for k=1:size(davar1, 1)
for i=1:numel(s)
switch davar1(k,:).([s{i} '_CHECK']) % I even tried insert (j) here and do it in the for loop but error says Index exceeds the number of array elements (2).
case 'New York'
p(i).FaceColor = 'g';
case 'California'
p(i).FaceColor = 'y';
case 'Illinois'
p(i).FaceColor = 'r';
case 'Texas '
p(i).FaceColor = 'k';
case 'Ohio'
p(i).FaceColor = 'b';
case 'North Carolina'
p(i).FaceColor = 'c';
case 'Tennessee'
p(i).FaceColor = 'w';
end
end
exportgraphics(ax, ['filename' num2str(k) '.png']);
end
I saw some people say save figure as .png then go to windows Microsoft Office PowerPoint and make your picture background transparent but I have over 200 images and it would be awesome if Matlab can do it. Please guid me how I can export my figure in transparent mode.
Thank you all

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 12 de Abr. de 2020
Editada: Ameer Hamza el 12 de Abr. de 2020
Call export_fig with additional inputs
export_fig('filename', '-dpng', '-transparent', '-r300'); % -r300 is the PPI value, default resolution is low

4 comentarios

BN
BN el 12 de Abr. de 2020
Thank you so much again.
Ameer Hamza
Ameer Hamza el 12 de Abr. de 2020
Glad to be of help.
John Mungall
John Mungall el 21 de En. de 2021
This was remarkably helpful. I am very grateful.
In my case, the last three lines of my test were:
scatter(x,y,sz,c,'filled');
filename = 'scattertransparent2';
export_fig(filename, '-dpng', '-transparent', '-r300'); % -r300 ...
After some "jiggling" with Word Size and Position, this let me produce a scatter plot overylying a jpg map with the map being situated nicely inside the plot axes. What a relief...
Yuan Zhang
Yuan Zhang el 2 de Jun. de 2021
Thanks Ameer, your code is really helpful!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Etiquetas

Preguntada:

BN
el 12 de Abr. de 2020

Comentada:

el 2 de Jun. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by