Skip to content

Commit e4cafd4

Browse files
committed
[WIP] DOC Fixes pandas-dev#8447 added examples
1 parent 2a0d23b commit e4cafd4

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

pandas/plotting/_core.py

+40-9
Original file line numberDiff line numberDiff line change
@@ -1935,9 +1935,16 @@ 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
1940-
1938+
Make a box-and-whisker plot from DataFrame column optionally grouped by some columns
1939+
or other inputs. The box extends from the Q1 to Q3 quartile values of the data,
1940+
with a line at the median (Q2). The whiskers extend from the edges of
1941+
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 `boxplot <https://en.wikipedia.org/wiki/Box_plot>`__
1947+
19411948
Parameters
19421949
----------
19431950
data : the pandas object holding the data
@@ -1958,29 +1965,53 @@ def plot_series(data, kind='line', ax=None, # Series unique
19581965
'dict' returns a dictionary whose values are the matplotlib
19591966
Lines of the boxplot;
19601967
'both' returns a namedtuple with the axes and dict.
1961-
19621968
When grouping with ``by``, a Series mapping columns to ``return_type``
19631969
is returned, unless ``return_type`` is None, in which case a NumPy
19641970
array of axes is returned with the same shape as ``layout``.
19651971
See the prose documentation for more.
1966-
19671972
`**kwds` : Keyword Arguments
19681973
All other plotting keyword arguments to be passed to
1969-
matplotlib's boxplot function
1970-
1974+
matplotlib's `boxplot <https://matplotlib.org/api/
1975+
_as_gen/matplotlib.pyplot.boxplot.html>`
1976+
function.
19711977
Returns
19721978
-------
19731979
lines : dict
19741980
ax : matplotlib Axes
19751981
(ax, lines): namedtuple
1976-
19771982
Notes
19781983
-----
19791984
Use ``return_type='dict'`` when you want to tweak the appearance
19801985
of the lines after plotting. In this case a dict containing the Lines
19811986
making up the boxes, caps, fliers, medians, and whiskers is returned.
1982-
"""
19831987
1988+
>>> df = pd.DataFrame({u'stratifying_var': np.random.uniform(0, 100, 20),
1989+
u'price': np.random.normal(100, 5, 20),
1990+
u'demand': np.random.normal(100, 10, 20)})
1991+
1992+
>>> df[u'quartiles'] = pd.qcut(df[u'stratifying_var'], 4,
1993+
labels=[u'0-25%', u'25-50%', u'50-75%', u'75-100%'])
1994+
1995+
>>> df
1996+
1997+
To plot the boxplot of the `demand` just put:
1998+
1999+
>>> df.boxplot(column=u'demand', by=u'quartiles')
2000+
2001+
Use `grid=False` to hide the grid:
2002+
2003+
>>> df.boxplot(column=u'demand', by=u'quartiles',grid=False)
2004+
2005+
Optionally, the layout can be changed by setting `layout=(rows, cols)`:
2006+
2007+
>>> df.boxplot(column=[u'price',u'demand'], by=u'quartiles', layout=(1,2),
2008+
figsize=(8,5))
2009+
2010+
2011+
>>> df.boxplot(column=[u'price',u'demand'], by=u'quartiles', layout=(2,1),
2012+
figsize=(5,8))
2013+
2014+
"""
19842015

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

0 commit comments

Comments
 (0)