MATLAB中两个不同子图的x轴相同

use*_*243 2 matlab plot subplot matlab-figure

我想在MATLAB中的图中有一个直线和条形图.如何为两个图形使用相同的x轴?下面的条形图x轴应与上面的x轴相同.我希望保留比较数字的能力.

图链接:点击这里

anq*_*egi 8

你可以使用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')
Run Code Online (Sandbox Code Playgroud)

用法:

linkaxes(ax)链接Axes向量中指定的对象的x轴和y轴限制ax.该linkaxes功能选择包含所有链接轴的当前限制的限制.

linkaxes(ax, option)ax根据指定链接轴option.该option参数可以是下列值之一:

'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