>>>>> "David" == David Huard <[EMAIL PROTECTED]> writes:

    David> Hi, I have a function fig(x) that returns a subplot
    David> instance, and I'd like to make a new figure by calling this
    David> function twice.

    David> For example: def fig(x): s = subplot(111) return s.plot(x)

    David> and i wan't to do something like:

    David> fig = figure(figsize = (6,12)) fig.add_axes(fig(x1))
    David> fig.add_axes(fig(x2))

    David> ax1, ax2 = fig.get_axes() ax1.set_position([.125, .5, .75,
    David> .4])

    David> But it looks like the position is not understood relative
    David> to the new figure size, so it doesn't work.  Should it or
    David> is there a better way to do that ?

There are lots of problems with your code that makes it hard to
understand what you are trying to do.  Let's get some terminology
straight by way of commenting your code, then maybe you can describe
what you really want to do

def fig(x):
    # subplot creates an Axes instance on a regular grid; it will add
    # this Axes to the current Figure, and if no Figure exists, it will
    # create on.  If a current Figure exists, and you have already
    # created an Axes in it with subplot(111), this call simply makes
    # the Axes the current Axes.  Technically, it creates a Subplot,
    # which is derived from Axes
    s = subplot(111)

    # plot returns a list of Line2D objects, and so the function "fig"
    # is returning a list of lines
    return s.plot(x)

# this call creates a Figure instance
fig = figure(figsize = (6,12))

# add_axes is used to add an Axes to the figure.  It expects either an
# Axes instance, or a rectangle determined by [left, bottom, width,
# height]. You are passing it a list of lines, as noted above
fig.add_axes(fig(x1))
fig.add_axes(fig(x2))

# this returns a list of axes
ax1, ax2 = fig.get_axes()

# this sets the rectangle for the first Axes 
ax1.set_position([.125, .5, .75, .4])


OK, now that we have some terminology down and hopefully you can see
why you are failing, I'll try and guess what you want.  You want to
add an Axes to the current figure, and have them stacked one above the
other.  So on the first call, you basically have subplot(111), and on
the second call, you have two subplots, subplot(211) and subplot(212).

Something like

from pylab import figure, show

def pushax(fig, x):
   n = len(fig.axes)
   for i, ax in enumerate(fig.axes):
      print 'new gemo', n+1,1,i+1
      ax.change_geometry(n+1,1,i+1)
   ax = fig.add_subplot(n+1, 1, n+1)
   ax.plot(x)

fig = figure()
pushax(fig, [1,2,3,4])
pushax(fig, [1,4,9,16])
show()


See also the devel list, where Andrew Straw recently added a "Sizer"
model along the lines of wx sizers for axes placement.

Or I may have misunderstood what you want to do....

JDH

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to