Border-less tight subplot: figure size and save

31 visualizaciones (últimos 30 días)
Jon Jae
Jon Jae el 3 de Abr. de 2020
Comentada: Ameer Hamza el 3 de Abr. de 2020
hey!
I am trying to resize the figure and save it as a .png. Sadly, the command 'set(gcf,'position',[10,10,300,100])' is misbehaving (First opens figure in full screen, than makes it way to small, than moves the figure OFF screen).
Does somebody has experience with this issue? Any other recommendations to do border-ess subplots? I am afraid to go through the list and running into the same isse again.
Executable example code below.
Thanks everybody!!
%create data
TWNovle = rand([1 672])
TWRoldal = rand([1 672])
TWSuldal = rand([1 672])
SWNovle = rand([1 672])
SWRoldal = rand([1 672])
SWSuldal = rand([1 672])
PWNovle = rand([1 672])
PWRoldal = rand([1 672])
PWSuldal = rand([1 672])
xNames = ["C1", "C2", "C3", "C4"];
xTimes = [0:4]
color1 = [.7 .7 .7]
color2 = 'r'
color3 = 'black'
figure('name','subplot_er','Visible','off');
subplot_er(1,3,1);
plot(TWNovle, 'Color',color1); hold on; plot(TWSuldal, 'Color', color2);plot(TWRoldal, 'Color',color3);
xticks([xTimes * 168]); xticklabels(xNames);title('TW'); hold off;
subplot_er(1,3,2);
plot(PWNovle,'Color', color1); hold on; plot(PWSuldal, 'Color',color2);plot(PWRoldal, 'Color',color3);
xticks([xTimes* 168]); xticklabels(xNames);title('PW'); hold off;
subplot_er(1,3,3);
plot(SWNovle, 'Color',color1); hold on; plot(SWSuldal, 'Color',color2);plot(SWRoldal, 'Color',color3);
xticks([xTimes* 168]); xticklabels(xNames);title('SW'); hold off;
%set(gcf,'position',[10,10,300,100])
set(gcf,'Visible','on')
%save
outputFileName = sprintf('ZZ_result_%s.png', datestr(now,'mmddyy_HHMMSS'));
saveas(gcf,outputFileName)

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 3 de Abr. de 2020
subplot_er changes the figure units from pixels to normalized. You need to convert it back to pixels to set the position like that
set(gcf,'Unit','pixels')
set(gcf,'position',[10,10,800,300]) % <--- 800, 300 indicate the width and height of figure window
set(gcf,'Visible','on')
  2 comentarios
Jon Jae
Jon Jae el 3 de Abr. de 2020
Thank you, this made the trick. Didn't think of changing the units!
Ameer Hamza
Ameer Hamza el 3 de Abr. de 2020
Glad to be of help.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by