我有一个(3,4)个子图,每个子图显示散乱的情节。散射点的范围不同,所以我的一些图有轴x(0-30)和y(0-8),但有些有x(18-22)和y(4-7)。我已经将xlim设置为0 30,ylim设置为0 8,但这使我的轴永远不会低于0,高于30等等。
对于每个地块的起源,我如何将我的轴设为“粘住”(0,0),将Y和X的轴分别设为8和30。
TIA寻求任何帮助
对答案的评论更新:
下面的代码仍然存在相同的问题
%% plot
for i = 1:num_bins;
h = zeros(ceil(num_bins),1);
h(i)=subplot(4,3,i);
plotmatrix(current_rpm,current_torque)
end
linkaxes(h,'xy');
axis([0 30 0 8]);发布于 2013-03-21 15:38:51
要以编程方式设置轴边界,有几个有用的命令:
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这利用了xlim的零输入参数调用约定,它返回当前x限制的数组。同样的方法适用于ylim。
请注意,所有这些命令都应用于当前轴,因此,如果要创建子图,则需要在每个轴生成图形时执行一次缩放调用。
另一个有用的例子是linkaxes命令。这将动态地链接两幅图的轴限值,包括编程调整大小命令(如xlim )和UI操作(如pan和缩放)。例如:
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]);https://stackoverflow.com/questions/15551595
复制相似问题