8000 Merge pull request #7178 from bcongdon/boxplot-zorder · matplotlib/matplotlib@e801685 · GitHub
[go: up one dir, main page]

Skip to content

Commit e801685

Browse files
NelleVQuLogic
authored andcommitted
Merge pull request #7178 from bcongdon/boxplot-zorder
Boxplot zorder kwarg
1 parent 7e44d70 commit e801685

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Boxplot Zorder Keyword Argument
2+
-------------------------------
3+
4+
The ``zorder`` parameter now exists for :func:`boxplot`. This allows the zorder
5+
of a boxplot to be set in the plotting function call.
6+
7+
Example
8+
```````
9+
::
10+
11+
boxplot(np.arange(10), zorder=10)

lib/matplotlib/axes/_axes.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,7 +3110,7 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
31103110
showbox=None, showfliers=None, boxprops=None,
31113111
labels=None, flierprops=None, medianprops=None,
31123112
meanprops=None, capprops=None, whiskerprops=None,
3113-
manage_xticks=True, autorange=False):
3113+
manage_xticks=True, autorange=False, zorder=None):
31143114
"""
31153115
Make a box and whisker plot.
31163116
@@ -3123,7 +3123,7 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
31233123
showbox=True, showfliers=True, boxprops=None,
31243124
labels=None, flierprops=None, medianprops=None,
31253125
meanprops=None, capprops=None, whiskerprops=None,
3126-
manage_xticks=True, autorange=False):
3126+
manage_xticks=True, autorange=False, zorder=None):
31273127
31283128
Make a box and whisker plot for each column of ``x`` or each
31293129
vector in sequence ``x``. The box extends from the lower to
@@ -3235,6 +3235,9 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
32353235
``shownotches`` is also True. Otherwise, means will be shown
32363236
as points.
32373237
3238+
zorder : scalar, optional (None)
3239+
Sets the zorder of the boxplot.
3240+
32383241
Other Parameters
32393242
----------------
32403243
showcaps : bool, optional (True)
@@ -3409,15 +3412,15 @@ def _update_dict(dictionary, rc_name, properties):
34093412
medianprops=medianprops, meanprops=meanprops,
34103413
meanline=meanline, showfliers=showfliers,
34113414
capprops=capprops, whiskerprops=whiskerprops,
3412-
manage_xticks=manage_xticks)
3415+
manage_xticks=manage_xticks, zorder=zorder)
34133416
return artists
34143417

34153418
def bxp(self, bxpstats, positions=None, widths=None, vert=True,
34163419
patch_artist=False, shownotches=False, showmeans=False,
34173420
showcaps=True, showbox=True, showfliers=True,
34183421
boxprops=None, whiskerprops=None, flierprops=None,
34193422
medianprops=None, capprops=None, meanprops=None,
3420-
meanline=False, manage_xticks=True):
3423+
meanline=False, manage_xticks=True, zorder=None):
34213424
"""
34223425
Drawing function for box and whisker plots.
34233426
@@ -3428,7 +3431,7 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
34283431
showcaps=True, showbox=True, showfliers=True,
34293432
boxprops=None, whiskerprops=None, flierprops=None,
34303433
medianprops=None, capprops=None, meanprops=None,
3431-
meanline=False, manage_xticks=True):
3434+
meanline=False, manage_xticks=True, zorder=None):
34323435
34333436
Make a box and whisker plot for each column of *x* or each
34343437
vector in sequence *x*. The box extends from the lower to
@@ -3532,6 +3535,9 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
35323535
manage_xticks : bool, default = True
35333536
If the function should adjust the xlim and xtick locations.
35343537
3538+
zorder : scalar, default = None
3539+
The zorder of the resulting boxplot
3540+
35353541
Returns
35363542
-------
35373543
result : dict
@@ -3574,7 +3580,10 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
35743580
# empty list of xticklabels
35753581
datalabels = []
35763582

3577-
zorder = mlines.Line2D.zorder
3583+
# Use default zorder if none specified
3584+
if zorder is None:
3585+
zorder = mlines.Line2D.zorder
3586+
35783587
zdelta = 0.1
35793588
# box properties
35803589
if patch_artist:

lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,14 @@ def test_boxplot_bad_ci_1():
20312031
conf_intervals=[[1, 2]])
20322032

20332033

2034+
@cleanup
2035+
def test_boxplot_zorder():
2036+
x = np.arange(10)
2037+
fix, ax = plt.subplots()
2038+
assert ax.boxplot 5A10 (x)['boxes'][0].get_zorder() == 2
2039+
assert ax.boxplot(x, zorder=10)['boxes'][0].get_zorder() == 10
2040+
2041+
20342042
@cleanup
20352043
def test_boxplot_bad_ci_2():
20362044
x = np.linspace(-7, 7, 140)

0 commit comments

Comments
 (0)
0