matlab两个图共用一个x轴_matlab – 用一个y轴和两个x轴绘制两组数据

本文介绍如何在Matlab中让两个图形共享同一个x轴,其中一个图的x轴位于顶部,透明且无yticks。通过设置轴的位置、颜色、限制以及属性链接,可以实现不同数据集的并排展示。示例代码展示了如何创建这样的图形,并提供了图例和标签的添加方法。
摘要由CSDN通过智能技术生成

您可以在第一个轴(在同一位置)上创建第二个轴,其中

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值