Using inset_axes

The native Matplotlib method we just described gives good flexibility to adjust the position of the inset axes. When we want to set a quick location, inset_axes may be a good start. There are a number of predefined locations you may select with the keyword argument loc without the hassle of specifying the exact coordinates by trial and error. It can be set by the strings or integer index of the corresponding positions:

'upper right'  : 1,'upper left'   : 2,'lower left'   : 3,'lower right'  : 4,'right'        : 5,'center left'  : 6,'center right' : 7,'lower center' : 8,'upper center' : 9,'center'       : 10

To use this method, we first import the module:

from mpl_toolkits.axes_grid1.inset_locator import inset_axes

Here is an example of embedding ...

Get Matplotlib 2.x By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.