【问题标题】:Same x-axis for two different subplots in MATLABMATLAB中两个不同子图的相同x轴
【发布时间】:2017-08-06 03:51:21
【问题描述】:

我想在 MATLAB 中的图中有一个线和条形图。我怎样才能为两个图表设置相同的 x 轴?下面的条形图 x 轴应与上面的 x 轴相同。我要保留比较数字的能力。

图链接:Click Here

【问题讨论】:

  • 我认为照片上传有问题。我添加了图的链接。
  • 你的图链接好像失效了...

标签: matlab plot matlab-figure subplot


【解决方案1】:

你可以使用linkaxes函数:

figure
ax1 = subplot(2,2,1);
x1 = linspace(0,6);
y1 = sin(x1);
plot(x1,y1)

ax2 = subplot(2,2,2);
x2 = linspace(0,10);
y2 = sin(2*x2);
plot(x2,y2)

ax3 = subplot(2,2,[3,4]);
x3 = linspace(0,16);
y3 = sin(6*x3);
plot(x3,y3)

linkaxes([ax1,ax2,ax3],'x')

用法:

linkaxes(ax) 链接指定的Axes 对象的 x 轴和 y 轴范围 在矢量ax 中。 linkaxes 函数选择包含 所有链接轴的当前限制。

linkaxes(ax, option)根据指定的option链接坐标轴axoption 参数可以是以下值之一:

'x' 仅链接 x 轴。
'y' 仅链接 y 轴。
'xy' 链接 x 轴和 y 轴。
'off' 删除链接。

参考这里:https://www.mathworks.com/help/matlab/ref/linkaxes.html

如果您的 matlab 早于 2006 年,您可以按照以下步骤操作:https://www.mathworks.com/matlabcentral/fileexchange/7169-samexaxis-nice-subplots-with-same-x-axis

【讨论】:

    猜你喜欢
    • 2021-11-26
    • 1970-01-01
    • 2015-05-31
    • 1970-01-01
    • 2020-12-17
    • 2012-10-08
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多