Hi,

Jae-Joon Lee <lee.j.j...@...> writes:
> I had a few off-list conversation with Alan, and I'm also quite agree
> with him for this issue.
[...]
>  issue 2)  It is not easy (actually impossible) to make an axes
> spanning multiple cells.

Regarding this 2nd issue, I appreciated long ago the flexibility and ease-of-use
offered by super-mongo WINDOW command (e.g.
http://www.astro.princeton.edu/~rhl/sm/sm.html#SYN83). Basically, this would be
the same as accepting a tuple as plotNum argument in matplotlib subplot(numRows,
numCols, plotNum) to specify the extent of the composed subplot in terms of
atomic subplots, e.g.

ax1 = subplot(2,2,(1,3))
ax2 = subplot(2,2,2)
ax3 = subplot(2,2,4)

would produce the following layout:

+-------+-------+
|       |  ax2  |
|       |       |
|  ax1  +-------+
|       |  ax3  |
|       |       |
+-------+-------+

or 

ax1 = subplot(3,3,(1,5))
ax2 = subplot(3,3,(7,9))
ax3 = subplot(3,3,(3,6))

for 

+-------+---+
|       |   |
|  ax1  |ax3|
|       |   |
+-------+---+
|    ax2    |
+-----------+

My current naive implementation is the following:

def add_axes(fig, nrow, ncol, extent, **kwargs):

    pars = fig.subplotpars
    figW = pars.right-pars.left                 # Fig size
    figH = pars.top-pars.bottom
    subW = figW / (ncol + pars.wspace*(ncol-1)) # Sub-axes size
    subH = figH / (nrow + pars.hspace*(nrow-1))
    sepW = pars.wspace*subW                     # Separations
    sepH = pars.hspace*subH

    axL,axR,axB,axT = 1,0,1,0
    for num in extent:
        assert 0<num<=nrow*ncol
        irow, icol =  divmod(num-1, ncol)
        subL = pars.left + icol*(subW + sepW)
        subB = pars.top - (irow+1)*subH - irow*sepH
        axL = min(axL,subL)
        axR = max(axR,subL+subW)
        axB = min(axB,subB)
        axT = max(axT,subB+subH)
    axW = axR-axL
    axH = axT-axB

    return fig.add_axes([axL,axB,axW,axH], **kwargs)

fig = figure()
ax1 = add_axes(fig,3,3,(1,5))
ax2 = add_axes(fig,3,3,(7,9))
ax3 = add_axes(fig,3,3,(3,6))
ax1.plot(randn(10),'b.')
ax2.plot(randn(10),'r.')
ax3.plot(randn(10),'g.')
draw()

Cheers.



------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to