Skip to content

Commit c84829d

Browse files
committed
MEP28: fix rst syntax for code blocks
1 parent accd403 commit c84829d

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

doc/devel/MEP/MEP28.rst

+51-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Status
1111
..
1212
.. MEPs go through a number of phases in their lifetime:
1313
14-
- **Discussion**
14+
**Discussion**
1515
..
1616
.. - **Progress**: Consensus was reached on the mailing list and
1717
.. implementation work has begun.
@@ -95,6 +95,44 @@ This will be achieved in the following way:
9595
3. Outdated parameters from ``Axes.boxplot`` will be deprecated and
9696
later removed.
9797

98+
Importance
99+
----------
100+
101+
Since the limits of the whiskers are computed arithmetically, there
102+
is an implicit assumption of normality in box and whisker plots.
103+
This primarily affects which data points are classified as outliers.
104+
105+
Allowing transformations to the data and the results used to draw
106+
boxplots will allow users to opt-out of that assumption if the
107+
data are known to not fit a normal distribution.
108+
109+
Below is an example of how ``Axes.boxplot`` classifies outliers of lognormal
110+
data differently depending one these types of transforms.
111+
112+
.. plot::
113+
:include-source: true
114+
115+
import numpy as np
116+
import matplotlib.pyplot as plt
117+
from matplotlib import cbook
118+
np.random.seed(0)
119+
120+
fig, ax = plt.subplots(figsize=(4, 6))
121+
ax.set_yscale('log')
122+
data = np.random.lognormal(-1.75, 2.75, size=37)
123+
124+
stats = cbook.boxplot_stats(data, labels=['arimetic'])
125+
logstats = cbook.boxplot_stats(np.log(data), labels=['log-transformed'])
126+
127+
for lsdict in logstats:
128+
for key, value in lsdict.items():
129+
if key != 'label':
130+
lsdict[key] = np.exp(value)
131+
132+
stats.extend(logstats)
133+
ax.bxp(stats)
134+
fig.show()
135+
98136
Implementation
99137
==============
100138

@@ -209,7 +247,6 @@ This MEP can be divided into a few loosely coupled components:
209247
#. Removing redundant statistical options in ``Axes.boxplot``
210248
#. Shifting all styling parameter processing from ``Axes.boxplot`` to ``Axes.bxp``.
211249

212-
213250
With this approach, #2 depends and #1, and #4 depends on #3.
214251

215252
There are two possible approaches to #2. The first and most direct would
@@ -222,7 +259,8 @@ value of ``statfxn`` would be ``cbook.boxplot_stats``, but users could
222259
pass their own function. Then ``transform_in`` and ``tranform_out`` would
223260
then be passed as elements of the ``statfxn_args`` parameter.
224261

225-
.. python:
262+
.. code:: python
263+
226264
def boxplot_stats(data, ..., transform_in=None, transform_out=None):
227265
if transform_in is None:
228266
transform_in = lambda x: x
@@ -256,7 +294,8 @@ then be passed as elements of the ``statfxn_args`` parameter.
256294
257295
Both cases would allow users to do the following:
258296

259-
.. python:
297+
.. code:: python
298+
260299
fig, ax1 = plt.subplots()
261300
artists1 = ax1.boxplot_optionX(data, transform_in=np.log,
262301
transform_out=np.exp)
@@ -268,22 +307,25 @@ whiskers set differently depending on some attribute of the data.
268307

269308
This is available under the current API:
270309

271-
.. python:
310+
.. code:: python
311+
272312
fig, ax1 = plt.subplots()
273313
my_stats = my_box_stats(data, bootstrap_method='BCA',
274314
whisker_method='dynamic')
275315
ax1.bxp(my_stats)
276316
277317
And would be more concise with Option Two
278318

279-
.. python:
319+
.. code:: python
320+
280321
fig, ax = plt.subplots()
281322
statopts = dict(transform_in=np.log, transform_out=np.exp)
282323
ax.boxplot(data, ..., **statopts)
283324
284325
Users could also pass their own function to compute the stats:
285326

286-
.. python:
327+
.. code:: python
328+
287329
fig, ax1 = plt.subplots()
288330
ax1.boxplot(data, statfxn=my_box_stats, bootstrap_method='BCA',
289331
whisker_method='dynamic')
@@ -293,7 +335,8 @@ but in the context of downstream libraries like seaborn, its advantage
293335
is more apparent as the following would be possible without any patches
294336
to seaborn:
295337

296-
.. python:
338+
.. code:: python
339+
297340
import seaborn
298341
tips = seaborn.load_data('tips')
299342
g = seaborn.factorplot(x="day", y="total_bill", hue="sex", data=tips,

0 commit comments

Comments
 (0)