Hi guys,
I've been wanting to do something similar as well. Create a figure from
other figures. The function accepts a list of figures, and according to the
ratio (rows to columns) creates a bigger figure of appropriate size and
'copies' the axes into the new figure.
I calculate the positions and size of the subplots in the new figure
proportionately (ie. a value between 0 and 1), and then do a ax.set_position.
This seems to be broken somehow, the axes still think the size of the figure
they're in is the original figure's size. Even though I already moved them
over to the new larger figure. I've tried to hack this by simply passing in
values bigger then 1, but I can't get it to work.
If I don't make the new figure bigger everything works, though the labels
get a bit cramped then.
If someone can have a look and give me some advise it would be very
appreciated.
Regards,
Christiaan
_________________________
import math
from matplotlib.figure import *
def multisubplot(figures=[], ratio=1.0, wspace=0.0, hspace=0.0):
fig = Figure()
n = len(figures)
if n < 1:
fig.add_subplot(111)
return fig
# calculate number of rows and columns
columns = int(math.ceil(sqrt(float(n)/(ratio))))
rows = int(math.ceil(float(n)/float(columns)))
# resize the new figure
w_inches = figures[0].get_size_inches()[0]*(columns)
h_inches = figures[0].get_size_inches()[1]*(rows)
fig.set_size_inches(w_inches, h_inches, forward=True)
print fig.get_size_inches()
# calculate the spacing
wspace = wspace / (float(columns))
hspace = hspace / (float(rows))
# calculate the l,b,w,h of all subplots
width = 1/float(columns) - wspace
height = 1/float(rows) - hspace
positions = []
for i in range(rows):
for j in range(columns):
positions.append([(j)*(width + wspace) + wspace/2, \
(rows-i-1)*(height + hspace) + hspace/2 , \
width, height])
# hack broken axes scaling
for pos in positions:
print ''
#pos[0] = pos[0] * (columns)
#pos[1] = pos[1] * (rows)
#pos[2] = pos[2] * (columns)
#pos[3] = pos[3] * (rows)
print n
print 'columns', columns, 'rows', rows
print 'wspace', wspace, 'hspace', hspace
print 'width', width, 'height', height
for pos in positions:
print pos
for i in range(rows):
for j in range(columns):
x = i*(columns) + j
if x < n:
for ax in figures[x].axes:
figures[x].delaxes(ax)
ax.set_figure(fig)
fig.add_axes(ax)
ax.set_position(positions[x])
return fig
#create some figures to pass to our function
pl = []
for i in range(13):
fig = Figure()
ax = fig.add_subplot(111)
ax.plot([1,math.sin(i),2])
pl.append(fig)
figsub = multisubplot(pl,ratio=1, wspace=0.1, hspace=0.1)
_______________________________--
On 18/02/2008, Robin <[EMAIL PROTECTED]> wrote:
>
> Thanks very much for all your help.
>
>
> On Feb 18, 2008 3:44 PM, John Hunter <[EMAIL PROTECTED]> wrote:
> > It's not that it isn't supported, it's just rarely used and so may
> > have slowly broken over time. It is useful, so It would be worthwhile
> > for us to fix it. Are you using 0.91.2 or svn?
>
>
> I am using 0.91.2 at the moment (on Mac OS X - I think this was the
> downloaded binary). I could build from svn if you think it would make
> a difference.
>
> I guess for now I will use the function argument method, but I'm happy
> to keep this code around and provide what feedback I can.
>
> I suspect that if the subplot geometry was set to autoupdate when the
> window is resized as it is for a fresh subplot, then the overlapping
> axes might go away after a window resize. The missing xticks is a bit
> of a mystery though - they all seems to be there, just not shown. I
> tried setting them visible and redrawing but no luck.
>
> Thanks again,
>
>
> Robin
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users