Inset figure in MatLab 2

This post explains how to plot data in main-inset figure.
In inset figure a portion of main figure data is plotted in close-up.
Some people referred to it as figure-within-figure or figure-inside-figure.

To plot main-inset figure, follow the steps here:

  1. Create a handle to main figure
  2. Plot the data of main figure
  3. Now create an axes for the inset/child figure. Use ‘parent’ and ‘position’ info of main figure, while creating axes for inset
  4. Now plot selected data in inset figure

y=x.^2; z=x;
plot(x,y,x,z);                                       % main plot
axes('parent',hf1,'position',[0.20 0.65 0.25 0.25]); % normalized units are used for position
                                                     % parent - handle to main figure
                                                     % position - [x,y,width,height] of inset
plot(x(2:6),y(2:6),x(2:6),z(2:6));                   % inset plot


Leave a Comment

2 thoughts on “Inset figure in MatLab

  • Manjith

    Error using axes: width and height must be > 0. In my case y axis is from -5.5 to -3 and I need ti insert second plot between in y(-4.8 -3.8)

    • RF Geek Post author

      Hi Manjith,
      The position of subplot is normalized w.r.t main figure.
      Try position as [0.28,0.5,0.4,0.4] (Assumed width and height are same, and like to place inset vertically in the middle of main figure)