TightInset indeed should adjust for the text:
How to adjust figure size when using plotyy?
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm trying to adjust the figure size when using plotyy:
clc;
clear all;
t = 0:.1:4*pi;
y = sin(t);
figure(1);
set(gcf,'units','inches','renderer', 'painters');
pos = get(gcf,'pos');
set(gcf,'Units','inches',...
'Position',[pos(1) pos(2) 4 2]);
plot(t,y)
xlabel('Time(s)')
ylabel('y(t)')
title('Sin function')
legend('y=sin(t)')
axis([0 t(end) -1.5 1.5])
set(gca,...
'Units','normalized',...
'YTick',-1.5:.5:1.5,...
'XTick',0:t(end)/4:t(end),...
'FontUnits','points',...
'FontWeight','normal',...
'FontSize',9,...
'FontName','Times')
set(gca, 'Position', get(gca, 'OuterPosition') - ...
get(gca, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]);
figure(2);
set(gcf,'units','inches','renderer', 'painters');
pos = get(gcf,'pos');
set(gcf,'Units','inches',...
'Position',[pos(1) pos(2) 4 2]);
[haxes,hline1,hline2]=plotyy(t,y,t,t);
ylabel(haxes(1),'sin(t)')
ylabel(haxes(2),'45degree')
xlabel(haxes(1),'Time(s)')
title('Sin function')
set(haxes,...
'Units','normalized',...
'FontUnits','points',...
'FontWeight','normal',...
'FontSize',9,...
'FontName','Times')
set(haxes(1), 'Position', get(haxes(1), 'OuterPosition') - ...
get(haxes(1), 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 0 0; 0 0 0 1]-...
get(haxes(2), 'TightInset') * [0 0 0 0; 0 0 0 0; 0 0 1 0; 0 0 0 0]);
The example indicates that the procedure works well for plot but not for plotyy. It seems that when I use plot, TightInset takes into account the text on the bottom and on the top (as it should), but it doesn't take them into account when I use plotyy. But I don't understand why this is the case and how to fix it. Any ideas?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Two y-axis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!