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