@@ -1998,24 +1998,22 @@ def plot_series(data, kind='line', ax=None, # Series unique
19981998 ----------
19991999 column : str or list of str, optional
20002000 Column name or list of names, or vector.
2001- Can be any valid input to groupby.
2002- by : str or array-like
2003- Column in the DataFrame to groupby.
2004- ax : object of class matplotlib.axes.Axes, default `None`
2001+ Can be any valid input to :meth:`pandas.DataFrame.groupby`.
2002+ by : str or array-like, optional
2003+ Column in the DataFrame to :meth:`pandas.DataFrame.groupby`.
2004+ One box-plot will be done per value of columns in `by`.
2005+ ax : object of class matplotlib.axes.Axes, optional
20052006 The matplotlib axes to be used by boxplot.
20062007 fontsize : float or str
2007- Tick label font size in points or as a string (e.g., ‘large’)
2008- (see `matplotlib.axes.Axes.tick_params
2009- <https://matplotlib.org/api/_as_gen/
2010- matplotlib.axes.Axes.tick_params.html>`_).
2008+ Tick label font size in points or as a string (e.g., ‘large’).
20112009 rot : int or float, default 0
20122010 The rotation angle of labels (in degrees)
20132011 with respect to the screen coordinate sytem.
2014- grid : boolean, default ` True`
2012+ grid : boolean, default True
20152013 Setting this to True will show the grid.
20162014 figsize : A tuple (width, height) in inches
20172015 The size of the figure to create in matplotlib.
2018- layout : tuple (rows, columns) ( optional)
2016+ layout : tuple (rows, columns), optional
20192017 For example, (3, 5) will display the subplots
20202018 using 3 columns and 5 rows, starting from the top-left.
20212019 return_type : {None, 'axes', 'dict', 'both'}, default 'axes'
@@ -2026,22 +2024,13 @@ def plot_series(data, kind='line', ax=None, # Series unique
20262024 Lines of the boxplot.
20272025 * 'both' returns a namedtuple with the axes and dict.
20282026 * when grouping with ``by``, a Series mapping columns to
2029- ``return_type`` is returned (i.e.
2030- ``df.boxplot(column=['Col1','Col2'], by='var',return_type='axes')``
2031- may return ``Series([AxesSubplot(..),AxesSubplot(..)],
2032- index=['Col1','Col2'])``).
2027+ ``return_type`` is returned.
20332028
20342029 If ``return_type`` is `None`, a NumPy array
2035- of axes with the same shape as ``layout`` is returned
2036- (i.e. ``df.boxplot(column=['Col1','Col2'],
2037- by='var',return_type=None)`` may return a
2038- ``array([<matplotlib.axes._subplots.AxesSubplot object at ..>,
2039- <matplotlib.axes._subplots.AxesSubplot object at ..>],
2040- dtype=object)``).
2041- **kwds : Keyword Arguments (optional)
2030+ of axes with the same shape as ``layout`` is returned.
2031+ **kwds : Keyword Arguments, optional
20422032 All other plotting keyword arguments to be passed to
2043- `matplotlib.pyplot.boxplot <https://matplotlib.org/api/_as_gen/
2044- matplotlib.pyplot.boxplot.html#matplotlib.pyplot.boxplot>`_.
2033+ :func:`matplotlib.pyplot.boxplot`.
20452034
20462035 Returns
20472036 -------
@@ -2059,8 +2048,8 @@ def plot_series(data, kind='line', ax=None, # Series unique
20592048
20602049 See Also
20612050 --------
2062- matplotlib.pyplot.boxplot: Make a box and whisker plot.
2063- matplotlib.pyplot.hist: Make a hsitogram .
2051+ matplotlib.pyplot.boxplot : Make a box and whisker plot.
2052+ matplotlib.pyplot.hist : Make a histogram .
20642053
20652054 Notes
20662055 -----
@@ -2078,27 +2067,27 @@ def plot_series(data, kind='line', ax=None, # Series unique
20782067 :context: close-figs
20792068
20802069 >>> np.random.seed(1234)
2081- >>> df = pd.DataFrame(np.random.rand (10,4),
2070+ >>> df = pd.DataFrame(np.random.randn (10,4),
20822071 ... columns=['Col1', 'Col2', 'Col3', 'Col4'])
20832072 >>> boxplot = df.boxplot(column=['Col1', 'Col2', 'Col3'])
20842073
2085- Boxplots of variables distributions grouped by a third variable values
2086- can be created using the option ``by``. For instance:
2074+ Boxplots of variables distributions grouped by the values of a third
2075+ variable can be created using the option ``by``. For instance:
20872076
20882077 .. plot::
20892078 :context: close-figs
20902079
2091- >>> df = pd.DataFrame(np.random.rand (10,2), columns=['Col1', 'Col2'] )
2080+ >>> df = pd.DataFrame(np.random.randn (10,2), columns=['Col1', 'Col2'] )
20922081 >>> df['X'] = pd.Series(['A','A','A','A','A','B','B','B','B','B'])
20932082 >>> boxplot = df.boxplot(by='X')
20942083
2095- A list of strings (i.e. ``['X','Y']``) containing can be passed to boxplot
2084+ A list of strings (i.e. ``['X','Y']``) can be passed to boxplot
20962085 in order to group the data by combination of the variables in the x-axis:
20972086
20982087 .. plot::
20992088 :context: close-figs
21002089
2101- >>> df = pd.DataFrame(np.random.rand (10,3),
2090+ >>> df = pd.DataFrame(np.random.randn (10,3),
21022091 ... columns=['Col1', 'Col2', 'Col3'])
21032092 >>> df['X'] = pd.Series(['A','A','A','A','A','B','B','B','B','B'])
21042093 >>> df['Y'] = pd.Series(['A','B','A','B','A','B','A','B','A','B'])
@@ -2109,7 +2098,7 @@ def plot_series(data, kind='line', ax=None, # Series unique
21092098 .. plot::
21102099 :context: close-figs
21112100
2112- >>> df = pd.DataFrame(np.random.rand (10,2), columns=['Col1', 'Col2'])
2101+ >>> df = pd.DataFrame(np.random.randn (10,2), columns=['Col1', 'Col2'])
21132102 >>> df['X'] = pd.Series(['A','A','A','A','A','B','B','B','B','B'])
21142103 >>> boxplot = df.boxplot(by='X', layout=(2,1))
21152104
@@ -2121,6 +2110,73 @@ def plot_series(data, kind='line', ax=None, # Series unique
21212110 :context: close-figs
21222111
21232112 >>> boxplot = df.boxplot(grid=False, rot=45, fontsize=15)
2113+
2114+
2115+ The parameter ``return_type`` can be used to select the type of element
2116+ returned by `boxplot`. When ``return_type='axes'`` is selected,
2117+ the matplotlib axes on which the boxplot is drawn are returned:
2118+
2119+ >>> df.boxplot(column=['Col1','Col2'], return_type='axes')
2120+ <matplotlib.axes._subplots.AxesSubplot object at ...>
2121+
2122+ If selecting ``return_type='dict'`` a dictionary containing the
2123+ lines is returned:
2124+
2125+ >>> df.boxplot(column=['Col1','Col2'], return_type='dict')
2126+ {'boxes': [<matplotlib.lines.Line2D at ...>,
2127+ <matplotlib.lines.Line2D at ...>],
2128+ 'caps': [<matplotlib.lines.Line2D at ...>,
2129+ <matplotlib.lines.Line2D at ...>,
2130+ <matplotlib.lines.Line2D at ...>,
2131+ <matplotlib.lines.Line2D at ...>],
2132+ 'fliers': [<matplotlib.lines.Line2D at ...>,
2133+ <matplotlib.lines.Line2D at ...>],
2134+ 'means': [],
2135+ 'medians': [<matplotlib.lines.Line2D at ...>,
2136+ <matplotlib.lines.Line2D at ...>],
2137+ 'whiskers': [<matplotlib.lines.Line2D at ...>,
2138+ <matplotlib.lines.Line2D at ...>,
2139+ <matplotlib.lines.Line2D at ...>,
2140+ <matplotlib.lines.Line2D at ...>]}
2141+
2142+ If selecting ``return_type='both'``, a namedtuple with matplotlib axes and
2143+ Line objets is returned:
2144+
2145+ >>> df.boxplot(column=['Col1','Col2'], return_type='both')
2146+ Boxplot(ax=<matplotlib.axes._subplots.AxesSubplot object
2147+ at 0x115821128>, lines={'whiskers':
2148+ [<matplotlib.lines.Line2D object at ...>,
2149+ <matplotlib.lines.Line2D object at ...>,
2150+ <matplotlib.lines.Line2D object at ...>,
2151+ <matplotlib.lines.Line2D object at ...>],
2152+ 'caps': [<matplotlib.lines.Line2D object at ...>,
2153+ <matplotlib.lines.Line2D object at ...>,
2154+ <matplotlib.lines.Line2D object at ...>,
2155+ <matplotlib.lines.Line2D object at ...>],
2156+ 'boxes': [<matplotlib.lines.Line2D object at ...>,
2157+ <matplotlib.lines.Line2D object at ...>],
2158+ 'medians': [<matplotlib.lines.Line2D object at ...>,
2159+ <matplotlib.lines.Line2D object at ...>],
2160+ 'fliers': [<matplotlib.lines.Line2D object at ...>,
2161+ <matplotlib.lines.Line2D object at ...>], 'means': []})
2162+
2163+ When grouping with ``by``, a Series mapping columns to ``return_type``
2164+ is returned:
2165+
2166+
2167+ >>> df.boxplot(column=['Col1','Col2'], by='X', return_type='axes')
2168+ Col1 AxesSubplot(0.1,0.15;0.363636x0.75)
2169+ Col2 AxesSubplot(0.536364,0.15;0.363636x0.75)
2170+ dtype: object
2171+
2172+ If ``return_type`` is `None`, a NumPy array of axes with the same shape
2173+ as ``layout`` is returned:
2174+
2175+ >>> df.boxplot(column=['Col1','Col2'], by='X', return_type=None)
2176+ array([<matplotlib.axes._subplots.AxesSubplot object at ...>,
2177+ <matplotlib.axes._subplots.AxesSubplot object at ...>],
2178+ dtype=object)
2179+
21242180 """
21252181
21262182@Appender (_shared_docs ['boxplot' ] % _shared_doc_kwargs )
0 commit comments