From: <ef...@us...> - 2010-03-21 00:39:12
|
Revision: 8205 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8205&view=rev Author: efiring Date: 2010-03-21 00:39:04 +0000 (Sun, 21 Mar 2010) Log Message: ----------- pyplot: new sca() function suggested by LJJ Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/matplotlib/pyplot.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2010-03-20 23:24:29 UTC (rev 8204) +++ trunk/matplotlib/CHANGELOG 2010-03-21 00:39:04 UTC (rev 8205) @@ -1,3 +1,5 @@ +2010-03-20 Added pyplot.sca() function suggested by JJL. - EF + 2010-03-20 Added conditional support for new Tooltip API in gtk backend. - EF 2010-03-20 Changed plt.fig_subplot() to plt.subplots() after discussion on Modified: trunk/matplotlib/lib/matplotlib/pyplot.py =================================================================== --- trunk/matplotlib/lib/matplotlib/pyplot.py 2010-03-20 23:24:29 UTC (rev 8204) +++ trunk/matplotlib/lib/matplotlib/pyplot.py 2010-03-21 00:39:04 UTC (rev 8205) @@ -549,9 +549,20 @@ draw_if_interactive() return ret +def sca(ax): + """ + Set the current Axes instance to *ax*. The current Figure + is updated to the parent of *ax*. + """ + managers = _pylab_helpers.Gcf.get_all_fig_managers() + for m in managers: + if ax in m.canvas.figure.axes: + _pylab_helpers.Gcf.set_active(m) + m.canvas.figure.sca(ax) + return + raise ValueError("Axes instance argument was not found in a figure.") - def gca(**kwargs): """ Return the current axis instance. This can be used to control @@ -656,7 +667,7 @@ subplots, including the enclosing figure object, in a single call. Keyword arguments: - + nrows : int Number of rows of the subplot grid. Defaults to 1. @@ -670,7 +681,7 @@ If True, the Y axis will be shared amongst all subplots. squeeze : bool - + If True, extra dimensions are squeezed out from the returned axis object: - if only one subplot is constructed (nrows=ncols=1), the resulting single Axis object is returned as a scalar. @@ -696,7 +707,7 @@ - ax can be either a single axis object or an array of axis objects if more than one supblot was created. The dimensions of the resulting array can be controlled with the squeeze keyword, see above. - + **Examples:** x = np.linspace(0, 2*np.pi, 400) @@ -706,7 +717,7 @@ f, ax = plt.subplots() ax.plot(x, y) ax.set_title('Simple plot') - + # Two subplots, unpack the output array immediately f, (ax1, ax2) = plt.subplots(1, 2, sharey=True) ax1.plot(x, y) @@ -719,11 +730,11 @@ if subplot_kw is None: subplot_kw = {} - + fig = figure(**fig_kw) # Create empty object array to hold all axes. It's easiest to make it 1-d - # so we can just append subplots upon creation, and then + # so we can just append subplots upon creation, and then nplots = nrows*ncols axarr = np.empty(nplots, dtype=object) @@ -734,9 +745,9 @@ if sharey: subplot_kw['sharey'] = ax0 axarr[0] = ax0 - + # Note off-by-one counting because add_subplot uses the matlab 1-based - # convention. + # convention. for i in range(1, nplots): axarr[i] = fig.add_subplot(nrows, ncols, i+1, **subplot_kw) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |