Adding-custom-axes-within-a-subplot redux

View: New views
2 Messages — Rating Filter:   Alert me  

Adding-custom-axes-within-a-subplot redux

by George Nurser-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
The excellent transformations tutorial
http://matplotlib.sourceforge.net/users/transforms_tutorial.html
explained exactly what I needed to do to include inserts in my figures.
Furthermore, it suggested to me that I should be able to do without
some very ugly code I had written to convert the bounding box for a
new axis instance from Axes coordinates to Figure coordinates, by
simply writing

ax2 = fig.add_axes([l_axes,b_axes,width_axes,height_axes],transform=ax.transAxes)

However, this doesn't seem to work.
The workaround, suggested by Jae-Joon Lee earlier this year --
http://www.nabble.com/Adding-custom-axes-within-a-subplot-td22159536.html

Bbox = matplotlib.transforms.Bbox.from_bounds(l_axes,b_axes,width_axes,height_axes)
trans = ax.transAxes + fig.transFigure.inverted()
l, b, w, h = matplotlib.transforms.TransformedBbox(Bbox, trans).bounds
ax2 = fig.add_axes([l, b, w, h])

is far more elegant than my original code, but it seems a pity that
fig.add_axes can't accept the transform directly.

Regards, George Nurser.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Re: Adding-custom-axes-within-a-subplot redux

by Jae-Joon Lee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Oct 25, 2009 at 7:30 PM, George Nurser <gnurser@...> wrote:
> it seems a pity that
> fig.add_axes can't accept the transform directly.

While this is certainly possible, but it is a bit tricky to get it
correct due to the underlying design of the matplotlib. On the other
hand, I think it solves some problems, but not all. And the
axes_locator attribute in the current matplotlib is an attempt for a
more general solution.
For example, what you want can be achieved with something like below.

from mpl_toolkits.axes_grid.inset_locator import InsetPosition
ax= subplot(111)
ax2=axes([0, 0, 0, 0]) # The initial value is ignored in this example
ax2.set_axes_locator(InsetPosition(ax, [0.2, 0.2, 0.4, 0.4]))

Regards,

-JJ

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users