-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathMEP28.html
More file actions
553 lines (518 loc) · 49.1 KB
/
MEP28.html
File metadata and controls
553 lines (518 loc) · 49.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MEP28: Remove Complexity from Axes.boxplot — Matplotlib 3.0.2 documentation</title>
<link rel="stylesheet" href="../../_static/mpl.css"
type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css"
type="text/css" />
<link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" />
<link rel="stylesheet" href="../../_static/gallery.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Matplotlib 3.0.2 documentation"
href="../../_static/opensearch.xml"/>
<link rel="shortcut icon" href="../../_static/favicon.ico"/>
<link rel="index" title="Index" href="../../genindex.html"
/>
<link rel="search" title="Search" href="../../search.html"
/>
<link rel="top" title="Matplotlib 3.0.2 documentation" href="../../index.html" />
<link rel="up" title="Matplotlib Enhancement Proposals" href="index.html" />
<link rel="next" title="MEP29: Text light markup" href="MEP29.html" />
<link rel="prev" title="MEP27: decouple pyplot from backends" href="MEP27.html" />
<link rel="canonical" href="https://matplotlib.org/stable/devel/MEP/MEP28.html" />
<script data-domain="matplotlib.org" defer="defer" src="https://views.scientific-python.org/js/script.js"></script>
</head>
<body>
<div id="unreleased-message"> You are reading an old version of the documentation (v3.0.2). For the latest version see <a href="https://matplotlib.org/stable/devel/MEP/MEP28.html">https://matplotlib.org/stable/devel/MEP/MEP28.html</a></div>
<div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px; position: relative;">
<a href="../../index.html">
<div style="float: left; position: absolute; width: 496px; bottom: 0; padding-bottom: 24px"><span style="float: right; color: #789; background: white">Version 3.0.2</span></div>
<img src="../../_static/logo2.png" height="125px" border="0" alt="matplotlib"/></a>
<!-- The "Fork me on github" ribbon -->
<div id="forkongithub"><a href="https://github.com/matplotlib/matplotlib">Fork me on GitHub</a></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="MEP29.html" title="MEP29: Text light markup"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="MEP27.html" title="MEP27: decouple pyplot from backends"
accesskey="P">previous</a> |</li>
<li><a href="../../index.html">home</a>| </li>
<li><a href="../../gallery/index.html">examples</a>| </li>
<li><a href="../../tutorials/index.html">tutorials</a>| </li>
<li><a href="../../api/api_overview.html">API</a>| </li>
<li><a href="../../contents.html">docs</a> »</li>
<li><a href="../index.html" >The Matplotlib Developers' Guide</a> »</li>
<li><a href="index.html" accesskey="U">Matplotlib Enhancement Proposals</a> »</li>
</ul>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
<h3><a href="../../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">MEP28: Remove Complexity from Axes.boxplot</a><ul>
<li><a class="reference internal" href="#status">Status</a></li>
<li><a class="reference internal" href="#branches-and-pull-requests">Branches and Pull requests</a></li>
<li><a class="reference internal" href="#abstract">Abstract</a></li>
<li><a class="reference internal" href="#detailed-description">Detailed description</a><ul>
<li><a class="reference internal" href="#importance">Importance</a></li>
</ul>
</li>
<li><a class="reference internal" href="#implementation">Implementation</a><ul>
<li><a class="reference internal" href="#passing-transform-functions-to-cbook-boxplots-stats">Passing transform functions to <code class="docutils literal notranslate"><span class="pre">cbook.boxplots_stats</span></code></a></li>
<li><a class="reference internal" href="#simplifications-to-the-axes-boxplot-api-and-other-functions">Simplifications to the <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> API and other functions</a></li>
</ul>
</li>
<li><a class="reference internal" href="#backward-compatibility">Backward compatibility</a><ul>
<li><a class="reference internal" href="#schedule">Schedule</a></li>
<li><a class="reference internal" href="#anticipated-impacts-to-users">Anticipated Impacts to Users</a></li>
<li><a class="reference internal" href="#anticipated-impacts-to-downstream-libraries">Anticipated Impacts to Downstream Libraries</a></li>
</ul>
</li>
<li><a class="reference internal" href="#alternatives">Alternatives</a><ul>
<li><a class="reference internal" href="#variations-on-the-theme">Variations on the theme</a></li>
<li><a class="reference internal" href="#doing-less">Doing less</a></li>
<li><a class="reference internal" href="#doing-nothing">Doing nothing</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="../../contents.html">Documentation overview</a><ul>
<li><a href="../index.html">The Matplotlib Developers' Guide</a><ul>
<li><a href="index.html">Matplotlib Enhancement Proposals</a><ul>
<li>Previous: <a href="MEP27.html" title="previous chapter">MEP27: decouple pyplot from backends</a></li>
<li>Next: <a href="MEP29.html" title="next chapter">MEP29: Text light markup</a></li>
</ul></li>
</ul></li>
</ul></li>
</ul>
</div>
<div id="sidebar-pagesource" role="note" aria-label="source link"
style="margin-top: 1.5em; padding-top: 0.1em; border-top: 1px solid #86989b">
<a href="../../_sources/devel/MEP/MEP28.rst.txt"
style="color: #c0c0c0" rel="nofollow">Show Page Source</a>
</div>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="mep28-remove-complexity-from-axes-boxplot">
<h1>MEP28: Remove Complexity from Axes.boxplot<a class="headerlink" href="#mep28-remove-complexity-from-axes-boxplot" title="Permalink to this headline">¶</a></h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#status" id="id1">Status</a></li>
<li><a class="reference internal" href="#branches-and-pull-requests" id="id2">Branches and Pull requests</a></li>
<li><a class="reference internal" href="#abstract" id="id3">Abstract</a></li>
<li><a class="reference internal" href="#detailed-description" id="id4">Detailed description</a><ul>
<li><a class="reference internal" href="#importance" id="id5">Importance</a></li>
</ul>
</li>
<li><a class="reference internal" href="#implementation" id="id6">Implementation</a><ul>
<li><a class="reference internal" href="#passing-transform-functions-to-cbook-boxplots-stats" id="id7">Passing transform functions to <code class="docutils literal notranslate"><span class="pre">cbook.boxplots_stats</span></code></a></li>
<li><a class="reference internal" href="#simplifications-to-the-axes-boxplot-api-and-other-functions" id="id8">Simplifications to the <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> API and other functions</a></li>
</ul>
</li>
<li><a class="reference internal" href="#backward-compatibility" id="id9">Backward compatibility</a><ul>
<li><a class="reference internal" href="#schedule" id="id10">Schedule</a></li>
<li><a class="reference internal" href="#anticipated-impacts-to-users" id="id11">Anticipated Impacts to Users</a></li>
<li><a class="reference internal" href="#anticipated-impacts-to-downstream-libraries" id="id12">Anticipated Impacts to Downstream Libraries</a></li>
</ul>
</li>
<li><a class="reference internal" href="#alternatives" id="id13">Alternatives</a><ul>
<li><a class="reference internal" href="#variations-on-the-theme" id="id14">Variations on the theme</a></li>
<li><a class="reference internal" href="#doing-less" id="id15">Doing less</a></li>
<li><a class="reference internal" href="#doing-nothing" id="id16">Doing nothing</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="status">
<h2><a class="toc-backref" href="#id1">Status</a><a class="headerlink" href="#status" title="Permalink to this headline">¶</a></h2>
<p><strong>Discussion</strong></p>
</div>
<div class="section" id="branches-and-pull-requests">
<h2><a class="toc-backref" href="#id2">Branches and Pull requests</a><a class="headerlink" href="#branches-and-pull-requests" title="Permalink to this headline">¶</a></h2>
<p>The following lists any open PRs or branches related to this MEP:</p>
<ol class="arabic simple">
<li>Deprecate redundant statistical kwargs in <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code>: <a class="reference external" href="https://github.com/phobson/matplotlib/tree/MEP28-initial-deprecations">https://github.com/phobson/matplotlib/tree/MEP28-initial-deprecations</a></li>
<li>Deprecate redundant style options in <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code>: <a class="reference external" href="https://github.com/phobson/matplotlib/tree/MEP28-initial-deprecations">https://github.com/phobson/matplotlib/tree/MEP28-initial-deprecations</a></li>
<li>Deprecate passings 2D numpy arrays as input: None</li>
<li>Add pre- & post-processing options to <code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code>: <a class="reference external" href="https://github.com/phobson/matplotlib/tree/boxplot-stat-transforms">https://github.com/phobson/matplotlib/tree/boxplot-stat-transforms</a></li>
<li>Exposing <code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code> through <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> kwargs: None</li>
<li>Remove redundant statistical kwargs in <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code>: None</li>
<li>Remove redundant style options in <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code>: None</li>
<li>Remaining items that arise through discussion: None</li>
</ol>
</div>
<div class="section" id="abstract">
<h2><a class="toc-backref" href="#id3">Abstract</a><a class="headerlink" href="#abstract" title="Permalink to this headline">¶</a></h2>
<p>Over the past few releases, the <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> method has grown in
complexity to support fully customizable artist styling and statistical
computation. This lead to <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> being split off into multiple
parts. The statistics needed to draw a boxplot are computed in
<code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code>, while the actual artists are drawn by <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code>.
The original method, <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> remains as the most public API that
handles passing the user-supplied data to <code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code>, feeding
the results to <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code>, and pre-processing style information for
each facet of the boxplot plots.</p>
<p>This MEP will outline a path forward to rollback the added complexity
and simplify the API while maintaining reasonable backwards
compatibility.</p>
</div>
<div class="section" id="detailed-description">
<h2><a class="toc-backref" href="#id4">Detailed description</a><a class="headerlink" href="#detailed-description" title="Permalink to this headline">¶</a></h2>
<p>Currently, the <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> method accepts parameters that allow the
users to specify medians and confidence intervals for each box that
will be drawn in the plot. These were provided so that avdanced users
could provide statistics computed in a different fashion that the simple
method provided by matplotlib. However, handling this input requires
complex logic to make sure that the forms of the data structure match what
needs to be drawn. At the moment, that logic contains 9 separate if/else
statements nested up to 5 levels deep with a for loop, and may raise up to 2 errors.
These parameters were added prior to the creation of the <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code> method,
which draws boxplots from a list of dictionaries containing the relevant
statistics. Matplotlib also provides a function that computes these
statistics via <code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code>. Note that advanced users can now
either a) write their own function to compute the stats required by
<code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code>, or b) modify the output returned by <code class="docutils literal notranslate"><span class="pre">cbook.boxplots_stats</span></code>
to fully customize the position of the artists of the plots. With this
flexibility, the parameters to manually specify only the medians and their
confidences intervals remain for backwards compatibility.</p>
<p>Around the same time that the two roles of <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> were split into
<code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code> for computation and <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code> for drawing, both
<code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> and <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code> were written to accept parameters that
individually toggle the drawing of all components of the boxplots, and
parameters that individually configure the style of those artists. However,
to maintain backwards compatibility, the <code class="docutils literal notranslate"><span class="pre">sym</span></code> parameter (previously used
to specify the symbol of the fliers) was retained. This parameter itself
requires fairly complex logic to reconcile the <code class="docutils literal notranslate"><span class="pre">sym</span></code> parameters with the
newer <code class="docutils literal notranslate"><span class="pre">flierprops</span></code> parameter at the default style specified by <code class="docutils literal notranslate"><span class="pre">matplotlibrc</span></code>.</p>
<p>This MEP seeks to dramatically simplify the creation of boxplots for
novice and advanced users alike. Importantly, the changes proposed here
will also be available to downstream packages like seaborn, as seaborn
smartly allows users to pass arbitrary dictionaries of parameters through
the seaborn API to the underlying matplotlib functions.</p>
<p>This will be achieved in the following way:</p>
<blockquote>
<div><ol class="arabic simple">
<li><code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code> will be modified to allow pre- and post-
computation transformation functions to be passed in (e.g., <code class="docutils literal notranslate"><span class="pre">np.log</span></code>
and <code class="docutils literal notranslate"><span class="pre">np.exp</span></code> for lognormally distributed data)</li>
<li><code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> will be modified to also accept and naïvely pass them
to <code class="docutils literal notranslate"><span class="pre">cbook.boxplots_stats</span></code> (Alt: pass the stat function and a dict
of its optional parameters).</li>
<li>Outdated parameters from <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> will be deprecated and
later removed.</li>
</ol>
</div></blockquote>
<div class="section" id="importance">
<h3><a class="toc-backref" href="#id5">Importance</a><a class="headerlink" href="#importance" title="Permalink to this headline">¶</a></h3>
<p>Since the limits of the whiskers are computed arithmetically, there
is an implicit assumption of normality in box and whisker plots.
This primarily affects which data points are classified as outliers.</p>
<p>Allowing transformations to the data and the results used to draw
boxplots will allow users to opt-out of that assumption if the
data are known to not fit a normal distribution.</p>
<p>Below is an example of how <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> classifies outliers of lognormal
data differently depending one these types of transforms.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">plt</span>
<span class="kn">from</span> <span class="nn">matplotlib</span> <span class="kn">import</span> <span class="n">cbook</span>
<span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">6</span><span class="p">))</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_yscale</span><span class="p">(</span><span class="s1">'log'</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">lognormal</span><span class="p">(</span><span class="o">-</span><span class="mf">1.75</span><span class="p">,</span> <span class="mf">2.75</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">37</span><span class="p">)</span>
<span class="n">stats</span> <span class="o">=</span> <span class="n">cbook</span><span class="o">.</span><span class="n">boxplot_stats</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">labels</span><span class="o">=</span><span class="p">[</span><span class="s1">'arithmetic'</span><span class="p">])</span>
<span class="n">logstats</span> <span class="o">=</span> <span class="n">cbook</span><span class="o">.</span><span class="n">boxplot_stats</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">data</span><span class="p">),</span> <span class="n">labels</span><span class="o">=</span><span class="p">[</span><span class="s1">'log-transformed'</span><span class="p">])</span>
<span class="k">for</span> <span class="n">lsdict</span> <span class="ow">in</span> <span class="n">logstats</span><span class="p">:</span>
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">lsdict</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">!=</span> <span class="s1">'label'</span><span class="p">:</span>
<span class="n">lsdict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="n">stats</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">logstats</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">bxp</span><span class="p">(</span><span class="n">stats</span><span class="p">)</span>
<span class="n">fig</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>(<a class="reference external" href="../../devel/MEP/MEP28-1.py">Source code</a>, <a class="reference external" href="../../devel/MEP/MEP28-1.png">png</a>, <a class="reference external" href="../../devel/MEP/MEP28-1.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../../_images/MEP28-1.png" src="../../_images/MEP28-1.png" />
</div>
</div>
</div>
<div class="section" id="implementation">
<h2><a class="toc-backref" href="#id6">Implementation</a><a class="headerlink" href="#implementation" title="Permalink to this headline">¶</a></h2>
<div class="section" id="passing-transform-functions-to-cbook-boxplots-stats">
<h3><a class="toc-backref" href="#id7">Passing transform functions to <code class="docutils literal notranslate"><span class="pre">cbook.boxplots_stats</span></code></a><a class="headerlink" href="#passing-transform-functions-to-cbook-boxplots-stats" title="Permalink to this headline">¶</a></h3>
<p>This MEP proposes that two parameters (e.g., <code class="docutils literal notranslate"><span class="pre">transform_in</span></code> and
<code class="docutils literal notranslate"><span class="pre">transform_out</span></code> be added to the cookbook function that computes the
statistics for the boxplot function. These will be optional keyword-only
arguments and can easily be set to <code class="docutils literal notranslate"><span class="pre">lambda</span> <span class="pre">x:</span> <span class="pre">x</span></code> as a no-op when omitted
by the user. The <code class="docutils literal notranslate"><span class="pre">transform_in</span></code> function will be applied to the data
as the <code class="docutils literal notranslate"><span class="pre">boxplot_stats</span></code> function loops through each subset of the data
passed to it. After the list of statistics dictionaries are computed the
<code class="docutils literal notranslate"><span class="pre">transform_out</span></code> function is applied to each value in the dictionaries.</p>
<p>These transformations can then be added to the call signature of
<code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> with little impact to that method's complexity. This is
because they can be directly passed to <code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code>.
Alternatively, <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> could be modified to accept an optional
statistical function kwarg and a dictionary of parameters to be direcly
passed to it.</p>
<p>At this point in the implementation users and external libraries like
seaborn would have complete control via the <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> method. More
importantly, at the very least, seaborn would require no changes to its
API to allow users to take advantage of these new options.</p>
</div>
<div class="section" id="simplifications-to-the-axes-boxplot-api-and-other-functions">
<h3><a class="toc-backref" href="#id8">Simplifications to the <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> API and other functions</a><a class="headerlink" href="#simplifications-to-the-axes-boxplot-api-and-other-functions" title="Permalink to this headline">¶</a></h3>
<p>Simplifying the boxplot method consists primarily of deprecating and then
removing the redundant parameters. Optionally, a next step would include
rectifying minor terminological inconsistencies between <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code>
and <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code>.</p>
<p>The parameters to be deprecated and removed include:</p>
<blockquote>
<div><ol class="arabic simple">
<li><code class="docutils literal notranslate"><span class="pre">usermedians</span></code> - processed by 10 SLOC, 3 <code class="docutils literal notranslate"><span class="pre">if</span></code> blocks, a <code class="docutils literal notranslate"><span class="pre">for</span></code> loop</li>
<li><code class="docutils literal notranslate"><span class="pre">conf_intervals</span></code> - handled by 15 SLOC, 6 <code class="docutils literal notranslate"><span class="pre">if</span></code> blocks, a <code class="docutils literal notranslate"><span class="pre">for</span></code> loop</li>
<li><code class="docutils literal notranslate"><span class="pre">sym</span></code> - processed by 12 SLOC, 4 <code class="docutils literal notranslate"><span class="pre">if</span></code> blocks</li>
</ol>
</div></blockquote>
<p>Removing the <code class="docutils literal notranslate"><span class="pre">sym</span></code> option allows all code in handling the remaining
styling parameters to be moved to <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code>. This doesn't remove
any complexity, but does reinforce the single responsibility principle
among <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code>, <code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code>, and <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code>.</p>
<p>Additionally, the <code class="docutils literal notranslate"><span class="pre">notch</span></code> parameter could be renamed <code class="docutils literal notranslate"><span class="pre">shownotches</span></code>
to be consistent with <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code>. This kind of cleanup could be taken
a step further and the <code class="docutils literal notranslate"><span class="pre">whis</span></code>, <code class="docutils literal notranslate"><span class="pre">bootstrap</span></code>, <code class="docutils literal notranslate"><span class="pre">autorange</span></code> could
be rolled into the kwargs passed to the new <code class="docutils literal notranslate"><span class="pre">statfxn</span></code> parameter.</p>
</div>
</div>
<div class="section" id="backward-compatibility">
<h2><a class="toc-backref" href="#id9">Backward compatibility</a><a class="headerlink" href="#backward-compatibility" title="Permalink to this headline">¶</a></h2>
<p>Implementation of this MEP would eventually result in the backwards
incompatible deprecation and then removal of the keyword parameters
<code class="docutils literal notranslate"><span class="pre">usermedians</span></code>, <code class="docutils literal notranslate"><span class="pre">conf_intervals</span></code>, and <code class="docutils literal notranslate"><span class="pre">sym</span></code>. Cursory searches on
GitHub indicated that <code class="docutils literal notranslate"><span class="pre">usermedians</span></code>, <code class="docutils literal notranslate"><span class="pre">conf_intervals</span></code> are used by
few users, who all seem to have a very strong knowledge of matplotlib.
A robust deprecation cycle should provide sufficient time for these
users to migrate to a new API.</p>
<p>Deprecation of <code class="docutils literal notranslate"><span class="pre">sym</span></code> however, may have a much broader reach into
the matplotlib userbase.</p>
<div class="section" id="schedule">
<h3><a class="toc-backref" href="#id10">Schedule</a><a class="headerlink" href="#schedule" title="Permalink to this headline">¶</a></h3>
<p>An accelerated timeline could look like the following:</p>
<ol class="arabic">
<li><p class="first">v2.0.1 add transforms to <code class="docutils literal notranslate"><span class="pre">cbook.boxplots_stats</span></code>, expose in <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code></p>
</li>
<li><p class="first">v2.1.0 Initial Deprecations , and using 2D numpy arrays as input</p>
<blockquote>
<div><ol class="loweralpha simple">
<li>Using 2D numpy arrays as input. The semantics around 2D arrays are generally confusing.</li>
<li><code class="docutils literal notranslate"><span class="pre">usermedians</span></code>, <code class="docutils literal notranslate"><span class="pre">conf_intervals</span></code>, <code class="docutils literal notranslate"><span class="pre">sym</span></code> parameters</li>
</ol>
</div></blockquote>
</li>
<li><p class="first">v2.2.0</p>
<blockquote>
<div><ol class="loweralpha simple">
<li>remove <code class="docutils literal notranslate"><span class="pre">usermedians</span></code>, <code class="docutils literal notranslate"><span class="pre">conf_intervals</span></code>, <code class="docutils literal notranslate"><span class="pre">sym</span></code> parameters</li>
<li>deprecate <code class="docutils literal notranslate"><span class="pre">notch</span></code> in favor of <code class="docutils literal notranslate"><span class="pre">shownotches</span></code> to be consistent with
other parameters and <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code></li>
</ol>
</div></blockquote>
</li>
<li><dl class="first docutils">
<dt>v2.3.0</dt>
<dd><ol class="first last loweralpha simple">
<li>remove <code class="docutils literal notranslate"><span class="pre">notch</span></code> parameter</li>
<li>move all style and artist toggling logic to <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code> such <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code>
is little more than a broker between <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code> and <code class="docutils literal notranslate"><span class="pre">cbook.boxplots_stats</span></code></li>
</ol>
</dd>
</dl>
</li>
</ol>
</div>
<div class="section" id="anticipated-impacts-to-users">
<h3><a class="toc-backref" href="#id11">Anticipated Impacts to Users</a><a class="headerlink" href="#anticipated-impacts-to-users" title="Permalink to this headline">¶</a></h3>
<p>As described above deprecating <code class="docutils literal notranslate"><span class="pre">usermedians</span></code> and <code class="docutils literal notranslate"><span class="pre">conf_intervals</span></code>
will likely impact few users. Those who will be impacted are almost
certainly advanced users who will be able to adapt to the change.</p>
<p>Deprecating the <code class="docutils literal notranslate"><span class="pre">sym</span></code> option may import more users and effort should
be taken to collect community feedback on this.</p>
</div>
<div class="section" id="anticipated-impacts-to-downstream-libraries">
<h3><a class="toc-backref" href="#id12">Anticipated Impacts to Downstream Libraries</a><a class="headerlink" href="#anticipated-impacts-to-downstream-libraries" title="Permalink to this headline">¶</a></h3>
<p>The source code (GitHub master as of 2016-10-17) was inspected for
seaborn and python-ggplot to see if these changes would impact their
use. None of the parameters nominated for removal in this MEP are used by
seaborn. The seaborn APIs that use matplotlib's boxplot function allow
user's to pass arbitrary <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> through to matplotlib's API. Thus
seaborn users with modern matplotlib installations will be able to take
full advantage of any new features added as a result of this MEP.</p>
<p>Python-ggplot has implemented its own function to draw boxplots. Therefore,
no impact can come to it as a result of implementing this MEP.</p>
</div>
</div>
<div class="section" id="alternatives">
<h2><a class="toc-backref" href="#id13">Alternatives</a><a class="headerlink" href="#alternatives" title="Permalink to this headline">¶</a></h2>
<div class="section" id="variations-on-the-theme">
<h3><a class="toc-backref" href="#id14">Variations on the theme</a><a class="headerlink" href="#variations-on-the-theme" title="Permalink to this headline">¶</a></h3>
<p>This MEP can be divided into a few loosely coupled components:</p>
<ol class="arabic simple">
<li>Allowing pre- and post-computation transformation function in <code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code></li>
<li>Exposing that transformation in the <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> API</li>
<li>Removing redundant statistical options in <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code></li>
<li>Shifting all styling parameter processing from <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> to <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code>.</li>
</ol>
<p>With this approach, #2 depends and #1, and #4 depends on #3.</p>
<p>There are two possible approaches to #2. The first and most direct would
be to mirror the new <code class="docutils literal notranslate"><span class="pre">transform_in</span></code> and <code class="docutils literal notranslate"><span class="pre">transform_out</span></code> parameters of
<code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code> in <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> and pass them directly.</p>
<p>The second approach would be to add <code class="docutils literal notranslate"><span class="pre">statfxn</span></code> and <code class="docutils literal notranslate"><span class="pre">statfxn_args</span></code>
parameters to <code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code>. Under this implementation, the default
value of <code class="docutils literal notranslate"><span class="pre">statfxn</span></code> would be <code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code>, but users could
pass their own function. Then <code class="docutils literal notranslate"><span class="pre">transform_in</span></code> and <code class="docutils literal notranslate"><span class="pre">transform_out</span></code> would
then be passed as elements of the <code class="docutils literal notranslate"><span class="pre">statfxn_args</span></code> parameter.</p>
<div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">boxplot_stats</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">...</span><span class="p">,</span> <span class="n">transform_in</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">transform_out</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="k">if</span> <span class="n">transform_in</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">transform_in</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span>
<span class="k">if</span> <span class="n">transform_out</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">transform_out</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span>
<span class="n">output</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">_d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
<span class="n">d</span> <span class="o">=</span> <span class="n">transform_in</span><span class="p">(</span><span class="n">_d</span><span class="p">)</span>
<span class="n">stat_dict</span> <span class="o">=</span> <span class="n">do_stats</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">stat_dict</span><span class="o">.</span><span class="n">item</span><span class="p">():</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">!=</span> <span class="s1">'label'</span><span class="p">:</span>
<span class="n">stat_dict</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">transform_out</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="n">output</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
<span class="k">return</span> <span class="n">output</span>
<span class="k">class</span> <span class="nc">Axes</span><span class="p">(</span><span class="o">...</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">boxplot_option1</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">...</span><span class="p">,</span> <span class="n">transform_in</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">transform_out</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="n">stats</span> <span class="o">=</span> <span class="n">cbook</span><span class="o">.</span><span class="n">boxplot_stats</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">...</span><span class="p">,</span>
<span class="n">transform_in</span><span class="o">=</span><span class="n">transform_in</span><span class="p">,</span>
<span class="n">transform_out</span><span class="o">=</span><span class="n">transform_out</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">bxp</span><span class="p">(</span><span class="n">stats</span><span class="p">,</span> <span class="o">...</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">boxplot_option2</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">...</span><span class="p">,</span> <span class="n">statfxn</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">statopts</span><span class="p">):</span>
<span class="k">if</span> <span class="n">statfxn</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">statfxn</span> <span class="o">=</span> <span class="n">boxplot_stats</span>
<span class="n">stats</span> <span class="o">=</span> <span class="n">statfxn</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">statopts</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">bxp</span><span class="p">(</span><span class="n">stats</span><span class="p">,</span> <span class="o">...</span><span class="p">)</span>
</pre></div>
</div>
<p>Both cases would allow users to do the following:</p>
<div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span><span class="p">,</span> <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">()</span>
<span class="n">artists1</span> <span class="o">=</span> <span class="n">ax1</span><span class="o">.</span><span class="n">boxplot_optionX</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">transform_in</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">,</span>
<span class="n">transform_out</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">)</span>
</pre></div>
</div>
<p>But Option Two lets a user write a completely custom stat function
(e.g., <code class="docutils literal notranslate"><span class="pre">my_box_stats</span></code>) with fancy BCA confidence intervals and the
whiskers set differently depending on some attribute of the data.</p>
<p>This is available under the current API:</p>
<div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span><span class="p">,</span> <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">()</span>
<span class="n">my_stats</span> <span class="o">=</span> <span class="n">my_box_stats</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">bootstrap_method</span><span class="o">=</span><span class="s1">'BCA'</span><span class="p">,</span>
<span class="n">whisker_method</span><span class="o">=</span><span class="s1">'dynamic'</span><span class="p">)</span>
<span class="n">ax1</span><span class="o">.</span><span class="n">bxp</span><span class="p">(</span><span class="n">my_stats</span><span class="p">)</span>
</pre></div>
</div>
<p>And would be more concise with Option Two</p>
<div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">()</span>
<span class="n">statopts</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">transform_in</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">,</span> <span class="n">transform_out</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">boxplot</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="o">...</span><span class="p">,</span> <span class="o">**</span><span class="n">statopts</span><span class="p">)</span>
</pre></div>
</div>
<p>Users could also pass their own function to compute the stats:</p>
<div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span><span class="p">,</span> <span class="n">ax1</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">()</span>
<span class="n">ax1</span><span class="o">.</span><span class="n">boxplot</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">statfxn</span><span class="o">=</span><span class="n">my_box_stats</span><span class="p">,</span> <span class="n">bootstrap_method</span><span class="o">=</span><span class="s1">'BCA'</span><span class="p">,</span>
<span class="n">whisker_method</span><span class="o">=</span><span class="s1">'dynamic'</span><span class="p">)</span>
</pre></div>
</div>
<p>From the examples above, Option Two seems to have only marginal benefit,
but in the context of downstream libraries like seaborn, its advantage
is more apparent as the following would be possible without any patches
to seaborn:</p>
<div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">seaborn</span>
<span class="n">tips</span> <span class="o">=</span> <span class="n">seaborn</span><span class="o">.</span><span class="n">load_data</span><span class="p">(</span><span class="s1">'tips'</span><span class="p">)</span>
<span class="n">g</span> <span class="o">=</span> <span class="n">seaborn</span><span class="o">.</span><span class="n">factorplot</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="s2">"day"</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="s2">"total_bill"</span><span class="p">,</span> <span class="n">hue</span><span class="o">=</span><span class="s2">"sex"</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">tips</span><span class="p">,</span>
<span class="n">kind</span><span class="o">=</span><span class="s1">'box'</span><span class="p">,</span> <span class="n">palette</span><span class="o">=</span><span class="s2">"PRGn"</span><span class="p">,</span> <span class="n">shownotches</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">statfxn</span><span class="o">=</span><span class="n">my_box_stats</span><span class="p">,</span> <span class="n">bootstrap_method</span><span class="o">=</span><span class="s1">'BCA'</span><span class="p">,</span>
<span class="n">whisker_method</span><span class="o">=</span><span class="s1">'dynamic'</span><span class="p">)</span>
</pre></div>
</div>
<p>This type of flexibility was the intention behind splitting the overall
boxplot API in the current three functions. In practice however, downstream
libraries like seaborn support versions of matplotlib dating back well
before the split. Thus, adding just a bit more flexibility to the
<code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code> could expose all the functionality to users of the
downstream libraries with modern matplotlib installation without intervention
from the downstream library maintainers.</p>
</div>
<div class="section" id="doing-less">
<h3><a class="toc-backref" href="#id15">Doing less</a><a class="headerlink" href="#doing-less" title="Permalink to this headline">¶</a></h3>
<p>Another obvious alternative would be to omit the added pre- and post-
computation transform functionality in <code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code> and
<code class="docutils literal notranslate"><span class="pre">Axes.boxplot</span></code>, and simply remove the redundant statistical and style
parameters as described above.</p>
</div>
<div class="section" id="doing-nothing">
<h3><a class="toc-backref" href="#id16">Doing nothing</a><a class="headerlink" href="#doing-nothing" title="Permalink to this headline">¶</a></h3>
<p>As with many things in life, doing nothing is an option here. This means
we simply advocate for users and downstream libraries to take advantage
of the split between <code class="docutils literal notranslate"><span class="pre">cbook.boxplot_stats</span></code> and <code class="docutils literal notranslate"><span class="pre">Axes.bxp</span></code> and let
them decide how to provide an interface to that.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2018 The Matplotlib development team.
<br />
Last updated on Nov 11, 2018.
Created using
<a href="http://sphinx-doc.org/">Sphinx</a> 1.8.1.
Doc version v3.0.2-2-g91e2d00a8.
</div>
</body>
<footer>
</footer>
</html>