我想在MATLAB中的图中有一个直线和条形图 . 如何为两个图形使用相同的x轴?下面的条形图x轴应与上面的x轴相同 . 我希望保留比较数字的能力 .
图链接:Click Here
你可以使用 linkaxes 功能:
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)链接向量ax中指定的Axes对象的x轴和y轴限制 . linkaxes函数选择包含所有链接轴的当前限制的限制 . linkaxes(ax,option)根据指定的选项链接轴ax . option参数可以是以下值之一:'x'仅链接x轴 . 'y'仅链接y轴 . 'xy'链接x轴和y轴 . 'off'删除链接 .
参考这里:https://www.mathworks.com/help/matlab/ref/linkaxes.html
如果你有一个比2006年更早的matlab,你可以这样做:https://www.mathworks.com/matlabcentral/fileexchange/7169-samexaxis-nice-subplots-with-same-x-axis
1 回答
你可以使用
linkaxes
功能:用法:
参考这里:https://www.mathworks.com/help/matlab/ref/linkaxes.html
如果你有一个比2006年更早的matlab,你可以这样做:https://www.mathworks.com/matlabcentral/fileexchange/7169-samexaxis-nice-subplots-with-same-x-axis