How to adding a plot to existing plot

Lizan · Aug 1, 2022 · 2.3K views
Question
I have a base plot in which I would like to add a smaller version of a second plot/figure ontop of the base plot at a certain location.   The second plot (or figure) is already saved as a .fig file. How do I import the .fig file and its data and plot it as is but smaller (so it fits inside the base plot without hiding base plot data) onto the base plot?
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 26, 2026
Hi Lizan,
 
This could be a two-parter. First, load the figure, get its children, then get the x and y data of its children. Second, create a second set of axes and plot. Here is an example of getting children of current axes and plotting the data on a smaller inset axis:
 
 
plot(1:5,11:15,'rx','markersize',12); 
hold on
plot(1.5:4.5,12:15,'bo','markersize',12); 

ch = get(gca,'children');
x1 = get(ch(1),'xdata'); 
y1 = get(ch(1),'ydata'); 
x2 = get(ch(2),'xdata'); 
y2 = get(ch(2),'ydata'); 

axes('pos',[.6 .2 .25 .25])
plot(x1,y1,'rp-')
hold on
plot(x2,y2,'bs-')

adding a plot

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!