我试图使用plotyy何时调整数字大小:如何在使用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]);
实例表明,该过程可以很好地用于情节而不是plotyy。看起来,当我使用plot时,TightInset考虑了底部和顶部的文本(应该是这样),但是当我使用plotyy时,它不考虑它们。但我不明白为什么会出现这种情况,以及如何解决这个问题。有任何想法吗?
[下面的代码是关系到我的评论所选择的答案]
figure(3);
set(gcf,'units','inches','renderer', 'painters');
pos = get(gcf,'pos');
set(gcf,'Units','inches',...
'Position',[pos(1) pos(2) 4 2]);
plot(t,y,'b');
set(gca,'YColor','b')
xlabel('Time(s)')
ylabel('y(t)')
title('Sin function')
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')
axesPosition = get(gca,'Position');
hNewAxes = axes('Position',axesPosition,...
'Color','none',...
'YLim',[0 10],...
'YAxisLocation','right',...
'XTick',[],...
'Box','off');
set(gca,'YColor',[0 .5 0]);
ylabel(hNewAxes,'45degree');
hold all
plot(hNewAxes,t,t,'color',[0 .5 0]);
hold off
完美!我也尝试了另一个手动设置另一个轴的建议。令人惊讶的是,没有必要调整位置以使所有事情变得紧张!我完全不知道为什么这个“神奇”发生。你知道这是为什么吗? (因为我不能在这里放置一个代码,所以我已经将它添加到了这个问题中) – capadocia 2015-02-01 02:00:04