Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 65e042f

Browse files
committed
pyplot: new sca() function suggested by LJJ
svn path=/trunk/matplotlib/; revision=8205
1 parent cd55943 commit 65e042f

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2010-03-20 Added pyplot.sca() function suggested by JJL. - EF
2+
13
2010-03-20 Added conditional support for new Tooltip API in gtk backend. - EF
24

35
2010-03-20 Changed plt.fig_subplot() to plt.subplots() after discussion on

lib/matplotlib/pyplot.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,18 @@ def delaxes(*args):
549549
draw_if_interactive()
550550
return ret
551551

552-
552+
def sca(ax):
553+
"""
554+
Set the current Axes instance to *ax*. The current Figure
555+
is updated to the parent of *ax*.
556+
"""
557+
managers = _pylab_helpers.Gcf.get_all_fig_managers()
558+
for m in managers:
559+
if ax in m.canvas.figure.axes:
560+
_pylab_helpers.Gcf.set_active(m)
561+
m.canvas.figure.sca(ax)
562+
return
563+
raise ValueError("Axes instance argument was not found in a figure.")
553564

554565

555566
def gca(**kwargs):
@@ -656,7 +667,7 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
656667
subplots, including the enclosing figure object, in a single call.
657668
658669
Keyword arguments:
659-
670+
660671
nrows : int
661672
Number of rows of the subplot grid. Defaults to 1.
662673
@@ -670,7 +681,7 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
670681
If True, the Y axis will be shared amongst all subplots.
671682
672683
squeeze : bool
673-
684+
674685
If True, extra dimensions are squeezed out from the returned axis object:
675686
- if only one subplot is constructed (nrows=ncols=1), the resulting
676687
single Axis object is returned as a scalar.
@@ -696,7 +707,7 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
696707
- ax can be either a single axis object or an array of axis objects if
697708
more than one supblot was created. The dimensions of the resulting array
698709
can be controlled with the squeeze keyword, see above.
699-
710+
700711
**Examples:**
701712
702713
x = np.linspace(0, 2*np.pi, 400)
@@ -706,7 +717,7 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
706717
f, ax = plt.subplots()
707718
ax.plot(x, y)
708719
ax.set_title('Simple plot')
709-
720+
710721
# Two subplots, unpack the output array immediately
711722
f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
712723
ax1.plot(x, y)
@@ -719,11 +730,11 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
719730

720731
if subplot_kw is None:
721732
subplot_kw = {}
722-
733+
723734
fig = figure(**fig_kw)
724735

725736
# Create empty object array to hold all axes. It's easiest to make it 1-d
726-
# so we can just append subplots upon creation, and then
737+
# so we can just append subplots upon creation, and then
727738
nplots = nrows*ncols
728739
axarr = np.empty(nplots, dtype=object)
729740

@@ -734,9 +745,9 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
734745
if sharey:
735746
subplot_kw['sharey'] = ax0
736747
axarr[0] = ax0
737-
748+
738749
# Note off-by-one counting because add_subplot uses the matlab 1-based
739-
# convention.
750+
# convention.
740751
for i in range(1, nplots):
741752
axarr[i] = fig.add_subplot(nrows, ncols, i+1, **subplot_kw)
742753

0 commit comments

Comments
 (0)