我试图使用两个不同的x轴绘制函数。正如您在图像中看到的那样,轴没有正确重叠!
我该如何解决?我已经将它设置为在两个轴上都有相同数量的刻度,但它没有帮助!
这是我使用的代码:
ax1 = gca;
set(gca, 'box', 'off')
xlabel('Frequency shift, \Delta\omega (/THz)');
ylabel('Autocorrelation, F_{2}');
ylim([0.0,1]);
xlim([0, 10])
xlimits = get(ax1,'XLim');
ylimits = get(ax1,'YLim');
xinc = (xlimits(2)-xlimits(1))/5;
yinc = (ylimits(2)-ylimits(1))/5;
set(ax1,'XTick',[xlimits(1):xinc:xlimits(2)],...
'YTick',[ylimits(1):yinc:ylimits(2)])
ax1.XColor = 'b';
ax1.YColor = 'b';
ax1_pos = ax1.Position;
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
ax2 = gca;
xlim([0, 2.5]) %in nm (note two pi)
ylim([0.0,1]);
xlimits = get(ax2,'XLim');
ylimits = get(ax2,'YLim');
xinc = (xlimits(2)-xlimits(1))/5;
yinc = (ylimits(2)-ylimits(1))/5;
set(ax2,'XTick',[xlimits(1):xinc:xlimits(2)],...
'YTick',[ylimits(1):yinc:ylimits(2)])
xlabel('Wavelength shift, \Delta\omega(/nm)');
ylabel('Autocorrelation, F_{2}');
ax2 = gca;
%set(ax,'XMinorTick','on','YMinorTick','off')
ax2.FontSize = 15;
ax2.Box = 'on';
ax2.LineWidth = 2;
set(gca, 'box', 'off')
set(findall(gcf,'type','text'),'FontSize',15);
答案 0 :(得分:0)
尝试一下
ax1_pos = get(gca,'Position');
ax2 = axes('Position', [ax1_pos(1) (ax1_pos(2) - 0.5) ax1_pos(3) ax1_pos(4)]);