Border-less tight subplot: figure size and save
조회 수: 33 (최근 30일)
이전 댓글 표시
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
채택된 답변
Ameer Hamza
2020년 4월 3일
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')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!