Fernando Perez wrote: > While chatting today with John, he suggested that a better api for > this would be to return an *array* of supblots, so that one could > index them with a[i,j] for the plot in row i, column j.
That would be nice. > implemented this already, but before committing it, I have one doubt: > what to do when nrows==ncols==1, the single subplot case? I'm inclined > to return only the subplot instead of a one-element array, so that one > can say > > f, a = fig_subplot() > a.plot(...) > > instead of having to do > > f, a = fig_subplot() > a[0].plot(...) > But this means the return value of the function would be: > - fig, axis if nr=nc=1 > - fig, axis_array in all other cases. actually, wouldn't there be three options, essentially: scalar, 1-d, 2-d so the second example might be. f, a = fig_subplot() a[0,0].plot(...) Eric Firing wrote: > The behavior one wants depends on whether one is calling fig_subplot in > a program in which the number of subplots could range from 0 to n, or > whether the call is being made with the number of subplots hardwired. good point. > The latter may be most common, but the former seems like an important > use case. I suggest providing a kwarg, e.g. "squeeze=True" as the > default, to eliminate zero-size-dimensions from the array, and False for > the case where nrows and/or ncols could be zero but one wants to be able > to iterate over the resulting array regardless. this feels a bit ugly to me as well, though not too bad. Maybe this is too much magic, but could you look at what was passed in to the subplot call: I don't remember if you are following the figure.add_subplot() api, but: If nothing, then the user is clearly asking for a single axis. if (r,c,n) then the user is specifying a 2-d arrangement, even if r and c happen to be 1. I think the only two options should be scalar or 2-d array, it seems a bit much to have a 1-d array option as well. Also, IIUC correctly, Figure.add_subplot always returns a SINGLE axis -- you have to call it multiple times to get the whole set. Does this version return the whole set? -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel