Skip to content

Commit ecbae13

Browse files
committed
Improved the subplot function documentation and fixed the autogeneration
from boilerplate.
1 parent 43e0844 commit ecbae13

File tree

3 files changed

+40
-24
lines changed

3 files changed

+40
-24
lines changed

boilerplate.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ def %(func)s(%(argspec)s):
4747
%(ax)s = gca()
4848
# allow callers to override the hold state by passing hold=True|False
4949
%(washold)s = %(ax)s.ishold()
50-
%(sethold)s
50+
%(sethold)s
5151
if hold is not None:
5252
%(ax)s.hold(hold)
5353
try:
5454
%(ret)s = %(ax)s.%(func)s(%(call)s)
5555
draw_if_interactive()
5656
finally:
5757
%(ax)s.hold(%(washold)s)
58-
%(mappable)s
58+
%(mappable)s
5959
return %(ret)s
6060
"""
6161

@@ -199,7 +199,7 @@ def format_value(value):
199199
# For some commands, an additional line is needed to set the
200200
# color map
201201
if func in cmappable:
202-
mappable = cmappable[func] % locals()
202+
mappable = ' ' + cmappable[func] % locals()
203203
else:
204204
mappable = ''
205205

@@ -232,7 +232,7 @@ def format_value(value):
232232
# argument in front of it since it would gobble one of the
233233
# arguments the user means to pass via *args)
234234
if varargs:
235-
sethold = "hold = %(varkw)s.pop('hold', None)" % locals()
235+
sethold = " hold = %(varkw)s.pop('hold', None)" % locals()
236236
elif fmt is PLOT_TEMPLATE:
237237
args.append('hold')
238238
defaults = defaults + (None,)
@@ -306,6 +306,7 @@ def build_pyplot():
306306
pyplot.write('\n')
307307

308308
pyplot.writelines(boilerplate_gen())
309+
pyplot.write('\n')
309310

310311

311312
if __name__ == '__main__':

lib/matplotlib/pylab.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
specgram - a spectrogram plot
8484
spy - plot sparsity pattern using markers or image
8585
stem - make a stem plot
86-
subplot - make a subplot (numrows, numcols, axesnum)
86+
subplot - make a subplot (nrows, ncols, plot_number)
8787
subplots_adjust - change the params controlling the subplot positions of current figure
8888
subplot_tool - launch the subplot configuration tool
8989
suptitle - add a figure title

lib/matplotlib/pyplot.py

+34-19
Original file line numberDiff line numberDiff line change
@@ -711,32 +711,47 @@ def gca(**kwargs):
711711

712712
def subplot(*args, **kwargs):
713713
"""
714-
Create a new axes (subplot).
714+
Return a subplot axes positioned by the given grid definition.
715715
716-
Creating axes with::
716+
Typical call signature::
717717
718-
subplot(numRows, numCols, plotNum)
718+
subplot(nrows, ncols, plot_number)
719719
720-
where *plotNum* = 1 is the first plot number and increasing *plotNums*
721-
fill rows first. max(*plotNum*) == *numRows* * *numCols*
720+
Where *nrows* and *ncols* are used to notionally split the figure
721+
into ``nrows * ncols`` sub-axes, and *plot_number* is used to identify
722+
the particular subplot that this function is to create within the notional
723+
grid. *plot_number* starts at 1, increments across rows first and has a
724+
maximum of ``nrows * ncols``.
722725
723-
You can leave out the commas if *numRows* <= *numCols* <=
724-
*plotNum* < 10, as in::
726+
In the case when *nrows*, *ncols* and *plot_number* are all less than 10,
727+
a convenience exists, such that the a 3 digit number can be given instead,
728+
where the hundreds represent *nrows*, the tens represent *ncols* and the
729+
units represent *plot_number*. For instance::
725730
726-
subplot(211) # 2 rows, 1 column, first (upper) plot
731+
subplot(211)
727732
728-
``subplot(111)`` is the default axis.
733+
produces a subaxes in a figure which represents the top plot (i.e. the
734+
first) in a 2 row by 1 column notional grid (no grid actually exists,
735+
but conceptually this is how the returned subplot has been positioned).
729736
730-
New subplots that overlap old will delete the old axes. If you do
731-
not want this behavior, use
732-
:meth:`~matplotlib.figure.Figure.add_subplot` or the
733-
:func:`~matplotlib.pyplot.axes` command. Eg.::
737+
.. note::
734738
735-
from pylab import *
736-
plot([1,2,3]) # implicitly creates subplot(111)
737-
subplot(211) # overlaps, subplot(111) is killed
738-
plot(rand(12), rand(12))
739-
subplot(212, axisbg='y') # creates 2nd subplot with yellow background
739+
Creating a new subplot with a position which is entirely inside a
740+
pre-existing axes will trigger the larger axes to be deleted::
741+
742+
import matplotlib.pyplot as plt
743+
# plot a line, implicitly creating a subplot(111)
744+
plt.plot([1,2,3])
745+
# now create a subplot which represents the top plot of a grid
746+
# with 2 rows and 1 column. Since this subplot will overlap the
747+
# first, the plot (and its axes) previously created, will be removed
748+
plt.subplot(211)
749+
plt.plot(range(12))
750+
plt.subplot(212, axisbg='y') # creates 2nd subplot with yellow background
751+
752+
If you do not want this behavior, use the
753+
:meth:`~matplotlib.figure.Figure.add_subplot` method or the
754+
:func:`~matplotlib.pyplot.axes` function instead.
740755
741756
Keyword arguments:
742757
@@ -2997,7 +3012,7 @@ def stackplot(x, *args, **kwargs):
29973012
draw_if_interactive()
29983013
finally:
29993014
ax.hold(washold)
3000-
3015+
30013016
return ret
30023017

30033018
# This function was autogenerated by boilerplate.py. Do not edit as

0 commit comments

Comments
 (0)