@@ -1980,52 +1980,134 @@ def plot_series(data, kind='line', ax=None, # Series unique
1980
1980
1981
1981
1982
1982
_shared_docs ['boxplot' ] = """
1983
- Make a box plot from DataFrame column optionally grouped by some columns or
1984
- other inputs
1983
+ Make a box-and-whisker plot from DataFrame column optionally grouped
1984
+ by some columns or other inputs. The box extends from the Q1 to Q3
1985
+ quartile values of the data, with a line at the median (Q2).
1986
+ The whiskers extend from the edges of box to show the range of the data.
1987
+ Flier points (outliers) are those past the end of the whiskers.
1988
+ The position of the whiskers is set by default to 1.5 IQR (`whis=1.5``)
1989
+ from the edge of the box.
1990
+
1991
+ For further details see
1992
+ Wikipedia's entry for `boxplot <https://en.wikipedia.org/wiki/Box_plot/>`_.
1985
1993
1986
1994
Parameters
1987
1995
----------
1988
- data : the pandas object holding the data
1989
1996
column : column name or list of names, or vector
1990
- Can be any valid input to groupby
1997
+ Can be any valid input to groupby.
1991
1998
by : string or sequence
1992
- Column in the DataFrame to group by
1993
- ax : Matplotlib axes object, optional
1999
+ Column in the DataFrame to groupby.
2000
+ ax : Matplotlib axes object, (default `None`)
2001
+ The matplotlib axes to be used by boxplot.
1994
2002
fontsize : int or string
2003
+ The font-size used by matplotlib.
1995
2004
rot : label rotation angle
2005
+ The rotation angle of labels.
2006
+ grid : boolean( default `True`)
2007
+ Setting this to True will show the grid.
1996
2008
figsize : A tuple (width, height) in inches
1997
- grid : Setting this to True will show the grid
2009
+ The size of the figure to create in inches by default.
1998
2010
layout : tuple (optional)
1999
- (rows, columns) for the layout of the plot
2011
+ Tuple (rows, columns) used for the layout of the plot.
2000
2012
return_type : {None, 'axes', 'dict', 'both'}, default None
2001
2013
The kind of object to return. The default is ``axes``
2002
2014
'axes' returns the matplotlib axes the boxplot is drawn on;
2003
2015
'dict' returns a dictionary whose values are the matplotlib
2004
2016
Lines of the boxplot;
2005
2017
'both' returns a namedtuple with the axes and dict.
2006
-
2007
2018
When grouping with ``by``, a Series mapping columns to ``return_type``
2008
2019
is returned, unless ``return_type`` is None, in which case a NumPy
2009
2020
array of axes is returned with the same shape as ``layout``.
2010
2021
See the prose documentation for more.
2011
-
2012
- `**kwds` : Keyword Arguments
2022
+ kwds : Keyword Arguments (optional)
2013
2023
All other plotting keyword arguments to be passed to
2014
- matplotlib's boxplot function
2024
+ matplotlib's function.
2015
2025
2016
2026
Returns
2017
2027
-------
2018
2028
lines : dict
2019
2029
ax : matplotlib Axes
2020
- (ax, lines): namedtuple
2030
+ (ax, lines): namedtuple
2031
+
2032
+ See Also
2033
+ --------
2034
+ matplotlib.pyplot.boxplot: Make a box and whisker plot.
2021
2035
2022
2036
Notes
2023
2037
-----
2024
2038
Use ``return_type='dict'`` when you want to tweak the appearance
2025
2039
of the lines after plotting. In this case a dict containing the Lines
2026
2040
making up the boxes, caps, fliers, medians, and whiskers is returned.
2027
- """
2028
2041
2042
+ Examples
2043
+ --------
2044
+ .. plot::
2045
+ :context: close-figs
2046
+
2047
+ >>> np.random.seed(1234)
2048
+
2049
+ >>> df = pd.DataFrame({
2050
+ ... u'stratifying_var': np.random.uniform(0, 100, 20),
2051
+ ... u'price': np.random.normal(100, 5, 20),
2052
+ ... u'demand': np.random.normal(100, 10, 20)})
2053
+
2054
+ >>> df[u'quartiles'] = pd.qcut(
2055
+ ... df[u'stratifying_var'], 4,
2056
+ ... labels=[u'0-25%%', u'25-50%%', u'50-75%%', u'75-100%%'])
2057
+
2058
+ >>> df
2059
+ stratifying_var price demand quartiles
2060
+ 0 19.151945 106.605791 108.416747 0-25%%
2061
+ 1 62.210877 92.265472 123.909605 50-75%%
2062
+ 2 43.772774 98.986768 100.761996 25-50%%
2063
+ 3 78.535858 96.720153 94.335541 75-100%%
2064
+ 4 77.997581 100.967107 100.361419 50-75%%
2065
+ 5 27.259261 102.767195 79.250224 0-25%%
2066
+ 6 27.646426 106.590758 102.477922 0-25%%
2067
+ 7 80.187218 97.653474 91.028432 75-100%%
2068
+ 8 95.813935 103.377770 98.632052 75-100%%
2069
+ 9 87.593263 90.914864 100.182892 75-100%%
2070
+ 10 35.781727 99.084457 107.554140 0-25%%
2071
+ 11 50.099513 105.294846 102.152686 25-50%%
2072
+ 12 68.346294 98.010799 108.410088 50-75%%
2073
+ 13 71.270203 101.687188 85.541899 50-75%%
2074
+ 14 37.025075 105.237893 85.980267 25-50%%
2075
+ 15 56.119619 105.229691 98.990818 25-50%%
2076
+ 16 50.308317 104.318586 94.517576 25-50%%
2077
+ 17 1.376845 99.389542 98.553805 0-25%%
2078
+ 18 77.282662 100.623565 103.540203 50-75%%
2079
+ 19 88.264119 98.386026 99.644870 75-100%%
2080
+
2081
+ To plot the boxplot of the ``demand`` just put:
2082
+
2083
+ .. plot::
2084
+ :context: close-figs
2085
+
2086
+ >>> boxplot = df.boxplot(column=u'demand', by=u'quartiles')
2087
+
2088
+ Use ``grid=False`` to hide the grid:
2089
+
2090
+ .. plot::
2091
+ :context: close-figs
2092
+
2093
+ >>> boxplot = df.boxplot(column=u'demand', by=u'quartiles', grid=False)
2094
+
2095
+ Optionally, the layout can be changed by setting ``layout=(rows, cols)``:
2096
+
2097
+ .. plot::
2098
+ :context: close-figs
2099
+
2100
+ >>> boxplot = df.boxplot(column=[u'price',u'demand'],
2101
+ ... by=u'quartiles', layout=(1,2),
2102
+ ... figsize=(8,5))
2103
+
2104
+ .. plot::
2105
+ :context: close-figs
2106
+
2107
+ >>> boxplot = df.boxplot(column=[u'price',u'demand'],
2108
+ ... by=u'quartiles', layout=(2,1),
2109
+ ... figsize=(5,8))
2110
+ """
2029
2111
2030
2112
@Appender (_shared_docs ['boxplot' ] % _shared_doc_kwargs )
2031
2113
def boxplot (data , column = None , by = None , ax = None , fontsize = None ,
0 commit comments