Skip to content

Commit 3b13646

Browse files
onesandzeroesjreback
authored andcommitted
Boxplot by quartile example code
Add mpl_style option as cookbook currently doesn't have plots
1 parent 89502fc commit 3b13646

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

doc/source/cookbook.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
np.random.seed(123456)
1212
from pandas import *
1313
options.display.max_rows=15
14+
options.display.mpl_style='default'
1415
import pandas as pd
1516
randn = np.random.randn
1617
randint = np.random.randint
@@ -346,6 +347,24 @@ The :ref:`Plotting <visualization>` docs.
346347
`Generate Embedded plots in excel files using Pandas, Vincent and xlsxwriter
347348
<http://pandas-xlsxwriter-charts.readthedocs.org/en/latest/introduction.html>`__
348349

350+
`Boxplot for each quartile of a stratifying variable
351+
<http://stackoverflow.com/questions/23232989/boxplot-stratified-by-column-in-python-pandas>`__
352+
353+
.. ipython:: python
354+
355+
df = pd.DataFrame(
356+
{u'stratifying_var': np.random.uniform(0, 100, 20),
357+
u'price': np.random.normal(100, 5, 20)}
358+
)
359+
df[u'quartiles'] = pd.qcut(
360+
df[u'stratifying_var'],
361+
4,
362+
labels=[u'0-25%', u'25-50%', u'50-75%', u'75-100%']
363+
)
364+
365+
@savefig quartile_boxplot.png
366+
df.boxplot(column=u'price', by=u'quartiles')
367+
349368
350369
Data In/Out
351370
-----------

0 commit comments

Comments
 (0)