我正在尝试在MATLAB中的另一个子图中绘制一个子图。问题在于最终子图仅显示较小子图的一部分。在网上搜索后,这里似乎有一个选择是将子图保存到一个临时图形中,然后将其添加到最终的子图中。另一种方法是在最终图形中手动指定图的位置,即滚动自己的子图。我想知道是否有更优雅的方法。如果这是不可能的/不希望的行为,请提前道歉。我对代码如何运行的想法是:
someData = linspace(0,10);
subplot(2,2,1);
plotThing(someData);
subplot(2,2,2);
plot(cos(someData));
function [ out ] = plotThing( someData )
y1 = sin(someData);
y2 = sin(2*someData);
y3 = sin(4*someData);
y4 = sin(8*someData);
f = figure(4);
subplot(2,2,1)
plot(someData,y1)
subplot(2,2,2)
plot(someData,y2)
subplot(2,2,3)
plot(someData,y3)
subplot(2,2,4)
plot(someData,y4)
out = f;
end
我期望的行为是在最终图中有两件事,在顶部有四个项目的子图,在下面有一个图。任何建议都很好。
编辑-可接受答案的问题是,它将需要大量子图(在我的情况下为12x12)。经过一番思考和工作,我发现可以将子图的内容封装到uipanel中。这给出了子图的期望行为,该子图可以在较大比例图中作为一个单元来对待。实现此目的的代码如下所示:
plotThing(someData, [0, 0.5, 1, 0.5]);
panel2 = uipanel('Position', [0, 0, 1, 0.5]);
subplot(1,1,1,'Parent', panel2); %Strange but necessary as one cannot set the parent of a plot directly
plot(cos(someData));
function [ out ] = plotThing( someData, position )
panel = uipanel('Position', position);
y1 = sin(someData);
y2 = sin(2*someData);
y3 = sin(4*someData);
y4 = sin(8*someData);
subplot(2,2,1, 'Parent', panel)
plot(someData,y1)
subplot(2,2,2, 'Parent', panel)
plot(someData,y2)
subplot(2,2,3, 'Parent', panel)
plot(someData,y3)
subplot(2,2,4, 'Parent', panel)
plot(someData,y4)
end
这种广义解样子的结果:结果
通过告诉MATLAB子图的范围,您应该能够做到这一点,如下所示。
subplot(4,2,1); % create a plot with subplots in a grid of 4 x 2
plot(someData,y1); % subplot at first row, first column
subplot(4,2,2);
plot(someData,y2); % subplot at first row, second column
subplot(4,2,3);
plot(someData,y3);
subplot(4,2,4);
plot(someData,y4);
subplot(4,2,[5 6 7 8]); % subplot spanning the entire third and fourth row
plot(someData,y5); % change [5, 6, 7, 8] to change the span
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句