Skip to content

Commit

Permalink
Rename to Figure.subplots; typo fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
anntzer committed Oct 12, 2015
1 parent b6c2148 commit eded075
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
32 changes: 14 additions & 18 deletions lib/matplotlib/figure.py
Expand Up @@ -1002,8 +1002,8 @@ def add_subplot(self, *args, **kwargs):
self.stale = True
return a

def add_subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
squeeze=True, subplot_kw=None, gridspec_kw=None):
def subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
squeeze=True, subplot_kw=None, gridspec_kw=None):
"""
Add a set of subplots to this figure.
Expand All @@ -1029,10 +1029,10 @@ def add_subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
sharey : {"none", "all", "row", "col"} or bool, default: False
If *False*, or "none", each subplot has its own Y axis.
If *True*, or "all", all subplots will share an Y axis, and the x
If *True*, or "all", all subplots will share an Y axis, and the y
tick labels on all but the first column of plots will be invisible.
If "row", each subplot row will share an Y axis, and the x tick
If "row", each subplot row will share an Y axis, and the y tick
labels on all but the first column of plots will be invisible.
If "col", each subplot column will share an Y axis.
Expand All @@ -1042,16 +1042,15 @@ def add_subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
array:
- if only one subplot is constructed (nrows=ncols=1), the resulting
single Axes object is returned as a scalar.
single Axes object is returned as a scalar.
- for Nx1 or 1xN subplots, the returned object is a 1-d numpy
object array of Axes objects are returned as numpy 1-d arrays.
object array of Axes objects are returned as numpy 1-d arrays.
- for NxM subplots with N>1 and M>1 are returned as a 2d array.
If *False*, no squeezing at all is done: the returned axes object
is always a 2-d array of Axes instances, even if it ends up being
1x1.
If *False*, no squeezing at all is done: the returned object is
always a 2-d array of Axes instances, even if it ends up being 1x1.
subplot_kw : dict, default: {}
Dict with keywords passed to the
Expand All @@ -1066,7 +1065,7 @@ def add_subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
Returns
-------
ax : single Axes object or array of Axes objects
The addes axes. The dimensions of the resulting array can be
The added axes. The dimensions of the resulting array can be
controlled with the squeeze keyword, see above.
See Also
Expand Down Expand Up @@ -1114,30 +1113,27 @@ def add_subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
axarr[row, col] = self.add_subplot(gs[row, col], **subplot_kw)

# turn off redundant tick labeling
if sharex in ["col", "all"] and nrows > 1:
if sharex in ["col", "all"]:
# turn off all but the bottom row
for ax in axarr[:-1, :].flat:
for label in ax.get_xticklabels():
label.set_visible(False)
ax.xaxis.offsetText.set_visible(False)

if sharey in ["row", "all"] and ncols > 1:
if sharey in ["row", "all"]:
# turn off all but the first column
for ax in axarr[:, 1:].flat:
for label in ax.get_yticklabels():
label.set_visible(False)
ax.yaxis.offsetText.set_visible(False)

if squeeze:
# Reshape the array to have the final desired dimension (nrow,ncol),
# though discarding unneeded dimensions that equal 1. If we only have
# one subplot, just return it instead of a 1-element array.
# Discarding unneeded dimensions that equal 1. If we only have one
# subplot, just return it instead of a 1-element array.
return axarr.item() if axarr.size == 1 else axarr.squeeze()
else:
# returned axis array will be always 2-d, even if nrows=ncols=1
# Returned axis array will be always 2-d, even if nrows=ncols=1.
return axarr


def clf(self, keep_observers=False):
"""
Clear the figure.
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/pyplot.py
Expand Up @@ -1132,9 +1132,9 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
plt.subplots(2, 2, sharex=True, sharey=True)
"""
fig = figure(**fig_kw)
axs = fig.add_subplots(
nrows=nrows, ncols=ncols, sharex=sharex, sharey=sharey, squeeze=squeeze,
subplot_kw=subplot_kw, gridspec_kw=gridspec_kw)
axs = fig.subplots(nrows=nrows, ncols=ncols, sharex=sharex, sharey=sharey,
squeeze=squeeze, subplot_kw=subplot_kw,
gridspec_kw=gridspec_kw)
return fig, axs


Expand Down

0 comments on commit eded075

Please sign in to comment.