扩展x轴matlab,MATLAB:绘制双底x轴

您可以使用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')

结果

仍然不完美,但可用.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值