Adding custom axes within a subplot

I'm trying to insert a custom set of axes within a subplot, much like
the axes_demo.py. Only difference is, now I want an inset graph
inside each of a number of subplots. Using ASCII art, much like the
following:

-------------------|
                  >
                  >
         ----- |
         > > >
         ----- |
-------------------|

-------------------|
                  >
                  >
         ----- |
         > > >
         ----- |
-------------------|

Where the whole thing would be the figure, containing 2 subplots each
with an inset.

Is there any way to have the rect coordinates of
  fig.add_axes(rect)
to refer to the axes coordinates of the respective subplot, and not of
the complete figure? (In reality there are actually 12 subplots, not
only 2....

Or is there another easy way to accomplish this?

Johann

Johann Rohwer wrote:

I'm trying to insert a custom set of axes within a subplot, much like the axes_demo.py. Only difference is, now I want an inset graph inside each of a number of subplots. Using ASCII art, much like the following:

>-------------------|
> >
> ----- |
> > > >
> ----- |
>-------------------|

>-------------------|
> >
> ----- |
> > > >
> ----- |
>-------------------|

Where the whole thing would be the figure, containing 2 subplots each with an inset.

Is there any way to have the rect coordinates of
  fig.add_axes(rect)
to refer to the axes coordinates of the respective subplot, and not of the complete figure? (In reality there are actually 12 subplots, not only 2....

To answer my own question, after browsing the docstrings I came up with the following attached minimal script to illustrate a solution to the problem. However, it appears crufty. Specifically,

1. Can the fig.add_axes() call not take a transform directly as optional argument, like in fig.add_axes([.4, .1, .5, .3], transform=ax.transAxes)? This would appear the natural solution but does not work.

2. The transformed bounding box gives coordinates in points, necessitating the division by figure width and figure height to revert back to fractional coordinates.

3. Re-calculating [l, b, w, h] from tBbox seems cumbersome. Can the add_axes() not call a Bbox instance directly?

I'm sure I'm missing something obvious but don't have the time to delve into the transforms sourcecode, so any pointer is appreciated :slight_smile:

Johann

sub_subplot.py (752 Bytes)

Here is my modification.

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

Johann Rohwer wrote:

To answer my own question, after browsing the docstrings I came up with the
following attached minimal script to illustrate a solution to the problem.
However, it appears crufty. Specifically,

1. Can the fig.add_axes() call not take a transform directly as optional
argument, like in fig.add_axes([.4, .1, .5, .3], transform=ax.transAxes)?
This would appear the natural solution but does not work.

The axes position should be given in the normalized figure coordinates.

2. The transformed bounding box gives coordinates in points, necessitating
the division by figure width and figure height to revert back to fractional
coordinates.

With my modification, you don't need this anymore.

3. Re-calculating [l, b, w, h] from tBbox seems cumbersome. Can the
add_axes() not call a Bbox instance directly?

Also see my modification.
I'm sorry but I don't understand what you mean by "add_axes() not call
a Bbox instance directly?".

IHTH,

-JJ

···

On Mon, Feb 23, 2009 at 2:49 PM, Johann Rohwer <jr@...841...> wrote:

I'm sure I'm missing something obvious but don't have the time to delve into
the transforms sourcecode, so any pointer is appreciated :slight_smile:

Johann

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi JJ

Here is my modification.

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

Thanks for this - works like a charm. My experience with
transformations is very limited but I can see that they are very
powerful...

> 3. Re-calculating [l, b, w, h] from tBbox seems cumbersome. Can
> the add_axes() not call a Bbox instance directly?

Also see my modification.
I'm sorry but I don't understand what you mean by "add_axes() not
call a Bbox instance directly?".

This has been answered by your modification - I wasn't aware of
the .bounds attribute of a bounding box, which gives the required
input to add_axes().

Thanks again
Johann

···

On Monday, 23 February 2009, Jae-Joon Lee wrote: