File Exchange

image thumbnail

figure inset

version 1.2.0.0 (1.87 KB) by moshe lindner
The function plotting figure inside figure (main and inset) from 2 existing figures.

10 Downloads

Updated 26 Aug 2010

View Version History

View License

The function plotting figure inside figure (main and inset) from 2 existing figures.

Cite As

moshe lindner (2021). figure inset (https://www.mathworks.com/matlabcentral/fileexchange/28549-figure-inset), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (26)

Davide Perrone

Friedemann Klaß

Users of Matlab2019a (possibly lower) can interactively add legends to the 'main' part of the final figure using the add legend button in the figures menu

Hope this helps...

Umberto Maria Ciucani

I have the same problem of gaurav.

gaurav

Hi Linder ! thanks for the code . I have hard time for finding a way to toggle legend entry correspond to main figure. In my main figure I have 5 lines out of them I am assigning 3 of them as legend. It works fine in Fig 1(main fig) but in the final figure there is no legend to show. I used legend(h_m,'toggle') ans I saw that all 5 legend entries with error in the legend names (for legends I use latex interpreter, which were not decoded properly). Is there a way to get the desired legend in the final figure? Also I have a query regarding how to get desired axis position (origin) for inset figure?

thanks,

Aled

Degang

While this short piece of code does create an inset for simple plots, it will break for slightly more sophisticated plots, e.g., plots with legends. Besides, the position of the inset is hard-coded.

Carlos

I mistakenly added the comment as a tag. Deletion doesn't seem to be working for me. My apologies.

Aous

Thanks for a useful code.
Can one use this code to draw an insert inside a subplot? I tried doing so by commenting the line in the code that creates new figure but that didn't work.

Aous

Thanks for a useful code.
Can one use this code to draw an insert inside a subplot? I tried doing so by commenting the line in the code that creates new figure but that didn't work.

moshe lindner

Hi Suasn.
In ordet to do so, you should remove the command that open a new figure from the code (line 16).

Moshe.

Susan

Hi Moshe,

Thanks for this useful code. I'm having a bit of bother trying to do something. I plot figure(1); I wish to inset a magnified portion of figure(1) (i.e. figure(2)) into figure(1) itself. Is this possible with your code?

Susan

Hi Moshe,

Thanks for this useful code. I'm having a bit of bother trying to do something. I plot figure(1); I wish to inset a magnified portion of figure(1) (i.e. figure(2)) into figure(1) itself. Is this possible with your code?

Benjamin Pavie

Doug

v. nice, useful tool.

Nolan Conaway

Sam_K

Nikolaos Anesiadis

Great code. Simple and works absolutely fine.

moshe lindner

Hi dd.
try to change the last line in the code to:
set(h_inset,'Position', [.7*ax(1)+0.2*(ax(3)-inset_size) .5*ax(2)+ax(4)-inset_size inset_size inset_size])

dd

Hi,
How do you get it then at N-W position?
Thks

moshe lindner

Eric - thanks for your comment.

Erik

When using legends, the code does not work if a legend is added in fig1 or fig2 (referring to the notation in the inset_example.m file) before calling the inset function. Adding a legend to fig1 seems to give it two different axes, which confuses inset.m.

A legend can however, be added afterwards to the new figure containing the inset by adding the row legend(h_m,'toggle') or legend(h_i,'toggle') at the bottom of inset_example.m.

Thanks for a nice code!

Shatrughan

extremely useful and great !!! easy to work with...Keep rocking .........

moshe lindner

Hi Aditi.
You need no modify the last line in the function.
try to cahnge it to:
set(h_inset,'Position', [.7*ax(1)+ax(3)-inset_size 1.4*ax(2) inset_size inset_size])

Aditi Goswami

How do I change the position of the inset on the main plot, to say 'SouthEast'?

Marco Buiatti

I confirm the previous comment: simple to use, it does the job, the example is nicely illustrative.
Only bug: when I inserted it into a matlab function plotting several consecutive plots (main + inset), it did not work until I numbered figures with high numbers. I guess there's a trivial interference between the number of the composite figure (automatically the lowest available) and the number of the following figures.

Simple code that does the job. However, it would be nice to place the inset in a similar way as with the legends, i.e.,

legend('My_inset','Location','SouthEast');

It works though!

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!