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