以编程方式设置轴边界有几个有用的命令:
axis([0 30 0 8]); %Sets all four axis bounds
或
xlim([0 30]); %Sets x axis limits
ylim([0 8]); %Sets y axis limits
要仅设置的两个X限制我通常使用这样的代码之一:
xlim([0 max(xlim)]); %Leaves upper x limit unchanged, sets lower x limit to 0
这需要一个零输入参数调用约定,返回当前x限制的数组。与ylim
一样。
请注意,所有这些命令都适用于当前轴,因此如果您要创建子图,则需要在构建图形时对每个轴执行一次缩放调用。
另一个有用的功能是linkaxes
命令。这将动态链接两个图的轴限制,包括编程调整大小命令(如xlim
)和UI操作(如平移和缩放)。例如:
a(1) = subplot(211),plot(rand(10,1), rand(10,1)); %Store axis handles in "a" vector
a(2) = subplot(212),plot(rand(10,1), rand(10,1)): %
linkaxes(a, 'xy');
axis([0 30 0 8]); %Note that all axes are now adjusted together
%Also try some manual zoom, pan operations using the UI buttons.
看你的代码,后期编辑,您的plotmatrix
功能的使用是复杂的事情。 plotmatrix
似乎创建自己的轴工作,所以你需要捕获这些句柄,并调整它们。 (另外,在将来将h = zeros(..)
带出循环)。
要获得plotmatrix
创建轴的句柄,请使用第二个返回参数,如下所示:[~, hAxes]=plotmatrix(current_rpm,current_torque);
。然后收集这些以供将来使用。
最后,axis
,xlim
,ylim
命令都作用于当前坐标轴(请参阅gca
)。但是plotmatrix
轴从不是最新的,因此axis
命令没有影响它们。您可以指定要执行的轴,如下所示:axis(hAxis, [0 30 0 8]);
。
把所有这些组合起来(的加入了一些变量定义,让您的代码来执行),这是什么样子:
%Define some dummy variables
current_rpm = rand(20,1)*30;
current_torque = rand(20,1)*8;
num_bins = 12;
%Loop to plot, collecting generated axis handles into "hAllAxes"
hAllAxes = [];
for i = 1:num_bins;
subplot(4,3,i);
[~, hCurrentAxes]=plotmatrix(current_rpm,current_torque);
hAllAxes = [hAllAxes hCurrentAxes]; %#ok
end
linkaxes(hAllAxes,'xy');
axis(hAllAxes,[0 30 0 8]);
感谢reply.I已尝试了,不过这只是套最小x值为0,但我仍然得到x轴在18-22范围内的图。我需要我的所有小区的规模完全相同。有什么想法? – mallow 2013-03-21 15:45:35
确保在绘制数据后设置坐标轴。 – Molly 2013-03-21 16:02:17
增加了一些更新。我怀疑'linkaxes'真的是你想要的。 – Pursuit 2013-03-21 16:08:25