您可以在第一个轴(在同一位置)上创建第二个轴,其中
XAxisLocation设置为“顶部”,没有颜色,因此它是透明的,没有yticks,并且它的
YLim链接到第一个轴的轴.此外,我们可以链接位置值,以确保如果我们调整其中一个轴,它们会调整大小以保持其外观.
figure;
% Create the first axes
hax1 = axes();
% Plot something here
xdata = 1:10;
hplot1 = line(xdata, log(xdata));
% Create a transparent axes on top of the first one with it's xaxis on top
% and no ytick marks (or labels)
hax2 = axes('Position', get(hax1, 'Position'), ... % Copy position
'XAxisLocation', 'top', ... % Put the x axis on top
'YAxisLocation', 'right', ... % Doesn't really matter
'xlim', [2 20], ... % Set XLims to fit our data
'Color', 'none', ... % Make it transparent
'YTick', []); % Don't show markers on y axis
% Plot data with a different x-range he