Border-less tight subplot: figure size and save
23 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jon Jae
am 3 Apr. 2020
Kommentiert: Ameer Hamza
am 3 Apr. 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 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 3 Apr. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!