how do I copy existing subplots and aggregate them into larger subplots

14 ビュー (過去 30 日間)
Chris Chow
Chris Chow 2016 年 8 月 12 日
コメント済み: Chang hsiung 2018 年 1 月 30 日
I have existing 2x1 grid subplots and would like to pair 2x1 subplots 2 of these plots side-by-side so it becomes a single 2x2 subplot. How can I do this and carry over each respective axes labels, titles, and legends to the new plot?
  1 件のコメント
Geoff Hayes
Geoff Hayes 2016 年 8 月 13 日
Chris - can you provide a sample of the code that produces the 2x1 subplots? Also, can you provide an image of what the result is now versus what you would like to achieve?

サインインしてコメントする。

回答 (4 件)

Kelly Kearney
Kelly Kearney 2016 年 8 月 16 日
If you don't have the code to reproduce the original figures (or if you simply prefer not to), you can use copyobj to copy the axes from one axis to another, and then simply change the position of those axes to match your desired subplot arrangement. In this example, I use a set of subplot axes ( h3.ax) as a template for the new positions of the copied axes ( h3.ax2).
% Your original figures
h1.fig = figure;
h1.ax(1) = subplot(2,1,1);
plot(rand(100,2), 'x');
h1.ax(2) = subplot(2,1,2);
plot(rand(100,2), 'o');
h2.fig = figure;
h2.ax(1) = subplot(2,1,1);
plot(rand(100,2), '+');
h2.ax(2) = subplot(2,1,2);
plot(rand(100,2), '.');
% The new one
h3.fig = figure;
h3.ax = gobjects(2);
for ii = 1:4
h3.ax(ii) = subplot(2,2,ii);
end
h3.ax = h3.ax';
h3.ax2 = gobjects(size(h3.ax));
h3.ax2(1,1) = copyobj(h1.ax(1), h3.fig);
h3.ax2(2,1) = copyobj(h1.ax(2), h3.fig);
h3.ax2(1,2) = copyobj(h2.ax(1), h3.fig);
h3.ax2(2,2) = copyobj(h2.ax(2), h3.fig);
for ii = 1:4
h3.ax2(ii).Position = h3.ax(ii).Position;
end
delete(h3.ax);

Benjamin
Benjamin 2016 年 8 月 16 日
One way is to use getframe() and then plot the 2 frames as images side-by-side. Of course you will not be able to further edit them as figures.

Thorsten
Thorsten 2016 年 8 月 16 日
編集済み: Thorsten 2016 年 8 月 16 日
You can initialise
spno = 1; % current subplot number
and then replace your 4 subplot commands with
subplot(2,2, spno), spno = spno + 1;

Chris Chow
Chris Chow 2016 年 8 月 16 日
Hi thanks.
Could you be a bit more specific from loading in a .fig file that was already organized as a 2x1 subplot to the shuffling for each subplot into a new 2x2 subplot? Thanks in advance
  2 件のコメント
Benjamin
Benjamin 2016 年 8 月 16 日
Chris, this should be a comment on someone's answer. It is not itself an answer.
Thorsten
Thorsten 2016 年 8 月 16 日
Do you have the matlab code to produce the 2x1 subplots? Then you can use my approach.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by