dividing up subplots?

hi all,

i am drawing a 2x3 set of subplots. i want it to eliminate the second
subplot of the first row and instead make the first subplot on the
first row take up two plots worth of space, i.e. have it so that the
first subplot takes up 2,3,1 and 2,3,2. In matlab, the command would
be something like subplot(2,3,[1,2]).

what is the way to do this in matplotlib? i have a lot of code
structured subplots and subplots_adjust, and i really want to avoid
switching to drawing my own axes if possible, as in this example:

http://matplotlib.sourceforge.net/examples/axes_grid/simple_axes_divider1.html

switching to this would be very complicated -- is there a way to do
this while still using the subplot command?

thanks.

Matpltlib's subplot does not support it as of now.

There a few work around you may try, but it will at least take a few
tens of lines of code. Attached is a way to do this by patching the
object method, which I personally do not prefer but may be one of the
easiest for normal users.

Also, there is a patch I once worked on, but haven't pushed into the
svn yet (i'm not sure if I ever will). So give it a try if you want.

http://article.gmane.org/gmane.comp.python.matplotlib.general/19097

Regards,

-JJ

import matplotlib.transforms as mtransforms

def expand_subplot(ax, num2):
    update_params_orig = ax.update_params

    ax._num2 = num2 - 1
    def _f(self=ax):
        num_orig = self._num

        self._num = self._num2
        update_params_orig()
        right, top = self.figbox.extents[2:]

        self._num = num_orig
        update_params_orig()
        left, bottom = self.figbox.extents[:2]

        self.figbox = mtransforms.Bbox.from_extents(left, bottom,
                                                    right, top)

    ax.update_params = _f
    ax.update_params()
    ax.set_position(ax.figbox)

ax = subplot(231)
expand_subplot(ax, 2)

···

On Thu, Dec 24, 2009 at 3:53 PM, per freem <perfreem@...287...> wrote:

i want it to eliminate the second
subplot of the first row and instead make the first subplot on the
first row take up two plots worth of space,

thanks very much. Using expand_subplot for that purpose worked great,
but I am now trying a variant of this and am having trouble getting it
to work.

I'd like to create a subplot that has two parts: the left part is a
square plot, and the right part is a 2x2 set of square subplots.
Something like this:

http://www.mathworks.com/access/helpdesk_archive_ja_JP/r2007/help/toolbox/matlab/ref/image/subplot_vert.gif

Except the left hand plot should have square axes. just imagine
taking a square plot and putting it on the left, and then making a 2x2
subplot, which each subplot is less than 1/4 the size of the square
plot on the left, and putting that on the right hand panel.

is there a way to do this in matplotlib?

thanks.

···

On Sat, Dec 26, 2009 at 10:55 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

On Thu, Dec 24, 2009 at 3:53 PM, per freem <perfreem@...287...> wrote:

i want it to eliminate the second
subplot of the first row and instead make the first subplot on the
first row take up two plots worth of space,

Matpltlib's subplot does not support it as of now.

There a few work around you may try, but it will at least take a few
tens of lines of code. Attached is a way to do this by patching the
object method, which I personally do not prefer but may be one of the
easiest for normal users.

Also, there is a patch I once worked on, but haven't pushed into the
svn yet (i'm not sure if I ever will). So give it a try if you want.

http://article.gmane.org/gmane.comp.python.matplotlib.general/19097

Regards,

-JJ

import matplotlib.transforms as mtransforms

def expand_subplot(ax, num2):
update_params_orig = ax.update_params

ax._num2 = num2 - 1
def _f(self=ax):
num_orig = self._num

   self\.\_num = self\.\_num2
   update\_params\_orig\(\)
   right, top = self\.figbox\.extents\[2:\]

   self\.\_num = num\_orig
   update\_params\_orig\(\)
   left, bottom = self\.figbox\.extents\[:2\]

   self\.figbox = mtransforms\.Bbox\.from\_extents\(left, bottom,
                                               right, top\)

ax.update_params = _f
ax.update_params()
ax.set_position(ax.figbox)

ax = subplot(231)
expand_subplot(ax, 2)

With subplots, I believe the answer is no. You may try to fiddle with
anchor positions of individual subplots, but this will only work for
some limited cases.

With axes_grid toolkit, yes.

-JJ

···

On Sun, Jan 3, 2010 at 4:30 PM, per freem <perfreem@...287...> wrote:

is there a way to do this in matplotlib?