Border-less tight subplot: figure size and save
31 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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)
0 comentarios
Respuesta aceptada
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Subplots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!