How to insert multiple figures of plots into a single figure with subplots?

41 次查看(过去 30 天)
I have searched for an answer to my question but it seems that people's questions generally involve inserting multiple plots into a single plot. I would like to make my doubt perfectly clear - I want to insert multiple FIGURES of plots (or subplots) into a SINGLE FIGURE with subplots. Also, the subplots have different axis labels and scales. Here is a pictorial representation of what I am trying to achieve.
This is what I have:
Figure1_2.JPG
This is what I want:
Figure3.JPG
Can someone please help me with how to do this? Your help is much appreciated.
Thanks.

采纳的回答

Astha Singh
Astha Singh 2018-12-12
Hi,
In this case, you need to use the MATLAB function 'copyobj()'. The following function:
new_handle = copyobj(h,p)
copies one or more graphic objects identified by 'h', to the parent object identified by 'p'.
The new parent must be appropriate for the copied object (for example, you can copy an axes only to figure or uipanel), this is why you cannot directly copy one 'figure object' to another figure.
As a work-around, you might find the following MATLAB Answer suitable for the query:
Although here, you would need to a priori define number of subplots in your destination figure.
The method broadly is to copy the 'children' (here axes objects) of your source figure to the destination figure and then modify the position properties of the axes to match to that of destination figure's subplot positions.

更多回答(1 个)

Pugazhenthi Sivasankar
Thank you very much! With some modifications, the code works well for my case.
  2 个评论
Anass LAMNAOUAR
Anass LAMNAOUAR 2021-2-24
hello Pugazhenthi Sivasankar,
Can you please put your script here i want to do the same thing as you.
Thank you in advance,
Daylín Góngora
Daylín Góngora 2022-2-7
编辑:Daylín Góngora 2022-2-7
PLOT 1
ax1 = gca;
PLOT 2
ax2 = gca;
...
fnew = figure;hold on;
for k = 1:6 %number of plots
if exist(['ax',num2str(k)],'var') == 1
temp = copyobj(eval(['ax',num2str(k)]),fnew);
subplot(2,3,k,temp); %update according to your desired layout
end
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by