Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1adb8bb

Browse files
committedMar 10, 2018
[WIP] DOC Fixes #8447 added examples
1 parent 2a0d23b commit 1adb8bb

File tree

1 file changed

+96
-14
lines changed

1 file changed

+96
-14
lines changed
 

‎pandas/plotting/_core.py

Lines changed: 96 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,52 +1935,134 @@ def plot_series(data, kind='line', ax=None, # Series unique
19351935

19361936

19371937
_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/>`_.
19401948
19411949
Parameters
19421950
----------
1943-
data : the pandas object holding the data
19441951
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.
19461953
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.
19491957
fontsize : int or string
1958+
The font-size used by matplotlib.
19501959
rot : label rotation angle
1960+
The rotation angle of labels.
1961+
grid : boolean( default `True`)
1962+
Setting this to True will show the grid.
19511963
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.
19531965
layout : tuple (optional)
1954-
(rows, columns) for the layout of the plot
1966+
Tuple (rows, columns) used for the layout of the plot.
19551967
return_type : {None, 'axes', 'dict', 'both'}, default None
19561968
The kind of object to return. The default is ``axes``
19571969
'axes' returns the matplotlib axes the boxplot is drawn on;
19581970
'dict' returns a dictionary whose values are the matplotlib
19591971
Lines of the boxplot;
19601972
'both' returns a namedtuple with the axes and dict.
1961-
19621973
When grouping with ``by``, a Series mapping columns to ``return_type``
19631974
is returned, unless ``return_type`` is None, in which case a NumPy
19641975
array of axes is returned with the same shape as ``layout``.
19651976
See the prose documentation for more.
1966-
1967-
`**kwds` : Keyword Arguments
1977+
kwds : Keyword Arguments (optional)
19681978
All other plotting keyword arguments to be passed to
1969-
matplotlib's boxplot function
1979+
matplotlib's function.
19701980
19711981
Returns
19721982
-------
19731983
lines : dict
19741984
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.
19761990
19771991
Notes
19781992
-----
19791993
Use ``return_type='dict'`` when you want to tweak the appearance
19801994
of the lines after plotting. In this case a dict containing the Lines
19811995
making up the boxes, caps, fliers, medians, and whiskers is returned.
1982-
"""
19831996
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+
"""
19842066

19852067
@Appender(_shared_docs['boxplot'] % _shared_doc_kwargs)
19862068
def boxplot(data, column=None, by=None, ax=None, fontsize=None,

0 commit comments

Comments
 (0)
Please sign in to comment.