您可以使用Victor May的方法来覆盖辅助轴,但这需要更多调整才能实际工作.
首先,让我们重新创建基本情节:
clear, close
time = [1/60, 1, 24, 24*7, 24*30, 24*30*6, 24*365, 24*365*10];
r = [110, 90, 80, 75, 70, 65, 63, 60];
% plot the data
semilogx(time, r, 'o-')
% adjust ticks and format of primary axes
xlim([0.005 1e6])
ylim([0 140])
tick = 10 .^ (-2 : 6);
set(gca, 'XTick', tick)
set(gca, 'XTickLabel', arrayfun(@num2str, tick, 'UniformOutput', false))
set(gca, 'XMinorTick', 'off')
set(gca, 'TickDir', 'out')
如果辅助轴具有与主要轴相同的位置,大小,轴限制和比例类型,并且其背景是透明的(否则数据将被隐藏),则仅覆盖辅助轴才能正常工作:
% put matching secondary axes on top with transparent background
pos = get(gca, 'Position');
axes('Position', pos)
set(gca, 'Color', 'none')
xlim([0.005 1e6])
ylim([0 140])
set(gca, 'XScale', 'log')
set(gca, 'XMinorTick', 'off')
set(gca, 'TickDir', 'out')
给它正确的刻度和刻度标签
% adjust ticks
set(gca, 'YTick', [])
set(gca, 'XTick', time)
label = {'1 min', '1 hour', '24 hours', '1 week', '1 month', '6 months', '1 year', '10 years'};
set(gca, 'XTickLabel', label)
结果是
– 不是我们想要的.
通过一个技巧,我们可以让二级轴的刻度和刻度标签进入……
% tinker with it
set(gca, 'XAxisLocation', 'top')
pos(4) = eps * pos(4);
set(gca, 'Position', pos)
……但那仍然不是我们想要的.
一个不同的策略:让我们不要叠加轴,而是将额外的刻度放在我们自己身上!
label = {'1 min', '1 hour', '24 hours', '1 week', '1 month', '6 months', '1 year', '10 years'};
line([time', time'], [0 2], 'Color', 'k')
text(time, 4 * ones(size(time)), label, 'Rotation', 90, 'VerticalAlignment', 'middle')
结果
仍然不完美,但可用.