Dear all,

asking question in a good way is art and I am trying to do that :-). I spent whole day trying to put an inset axes within another hosting axes the exact position I want.
and from here http://old.nabble.com/Adding-custom-axes-within-a-subplot-td22159536.html  Jae-Joon Lee  gave a good answer using only four lines:

    Bbox = matplotlib.transforms.Bbox.from_bounds(.4, .1, .5, .3)   #numbers in fraction of hosting axes
    trans = ax.transAxes + fig.transFigure.inverted()
    l, b, w, h = matplotlib.transforms.TransformedBbox(Bbox, trans).bounds
    axins = fig.add_axes([l, b, w, h])

It works fine. Now my question is I want inset axes to have 'equal' aspect because I want 1:1 ratio plot. and I found that using axins.set_aspect('equal')
will change the position of the inset axes. Then I tried to adjust the width and height of inset axes with the hosting axes aspect ratio before I draw it so that
I would expect they look already "aspect-equal" before I feed data to it. 

So my first question is,  How can I get the axes aspect ratio, axes.get_aspect() and  axes._aspect both give only 'auto' but not numerical value.
(I assume it's height/width ratio in terms of figure fraction or it's inverse?, I tried this but it doesn't work.)

another side-question, I have a feeling that understanding transform is of great value working with matplotlib. But I don't understand the
four lines above, and I can not find further information either in the matplotlib document or online. Is there any source except having
dig into source code? thanks!!!!!!!!

I make an example script below to show the problem (long but easy). I hope someone could offer some help. :-)

###script showing the problem
fig=plt.figure()
#plot two subplot to have ax aspect far from 'equal'
ax=fig.add_subplot(211)
a=np.arange(0,2*np.pi,0.1)
ax.plot(a,np.sin(a))
 
def create_inset_axes(x0,y0,width,height):  #the four numbers are x0,y0,width,height
    Bbox = matplotlib.transforms.Bbox.from_bounds(x0,y0,width,height)
    trans = ax.transAxes + fig.transFigure.inverted()
    l, b, w, h = matplotlib.transforms.TransformedBbox(Bbox, trans).bounds
    return fig.add_axes([l, b, w, h])
 
def get_axes_aspect_ratio(ax):
    box=ax.get_position()
    ratio=(box.x1-box.x0)/(box.y1-box.y0)
    return ratio
 
axins=create_inset_axes(0.1,0.05,0.2,0.2)
axins.plot(np.arange(10),'ro')
ax.text(0.35,0.15,'no any adjustment',transform=ax.transAxes)
 
axins=create_inset_axes(0.1, 0.3, 0.2, 0.2)
axins.plot(np.arange(10),'ro')
axins.set_aspect('equal')
ax.text(0.35,0.4,'explicitly set aspect as equal',transform=ax.transAxes)
 
axins=create_inset_axes(0.1, 0.55, 0.2, 0.2*ratio) #adjust the height by ax axes width/height ratio
axins.plot(np.arange(10),'ro')
ax.text(0.35,0.7,'adjust with hosting axes width/length ratio',transform=ax.transAxes)

cheers,

Chao
--
***********************************************************************************
Chao YUE
Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex
Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16
************************************************************************************