MATLAB 中两个不同子图的相同 x 轴
Same x-axis for two different subplots in MATLAB
我想在 MATLAB 的图形中绘制线条图和条形图。如何让两个图具有相同的 x 轴?下面的条形图 x 轴应该与上面的 x 轴相同。我想保留比较数字的能力。
图link:Click Here
您可以使用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)
links the x- and y-axis limits of the Axes
objects specified
in the vector ax
. The linkaxes
function chooses limits that incorporate the
current limits for all the linked axes.
linkaxes(ax, option)
links the axes ax
according to the specified option
.
The option
argument can be one of these values:
'x'
Link x-axis only.
'y'
Link y-axis only.
'xy'
Link x-axis and y-axis.
'off'
Remove linking.
此处参考: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
我想在 MATLAB 的图形中绘制线条图和条形图。如何让两个图具有相同的 x 轴?下面的条形图 x 轴应该与上面的 x 轴相同。我想保留比较数字的能力。
图link:Click Here
您可以使用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)
links the x- and y-axis limits of theAxes
objects specified in the vectorax
. Thelinkaxes
function chooses limits that incorporate the current limits for all the linked axes.
linkaxes(ax, option)
links the axesax
according to the specifiedoption
. Theoption
argument can be one of these values:
'x'
Link x-axis only.
'y'
Link y-axis only.
'xy'
Link x-axis and y-axis.
'off'
Remove linking.
此处参考: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