Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8d05a4

Browse files
authored
Merge pull request #7178 from bcongdon/boxplot-zorder
Boxplot zorder kwarg
2 parents e4da584 + 8c90b1c commit f8d05a4

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
@@ -3100,7 +3100,7 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
31003100
showbox=None, showfliers=None, boxprops=None,
31013101
labels=None, flierprops=None, medianprops=None,
31023102
meanprops=None, capprops=None, whiskerprops=None,
3103-
manage_xticks=True, autorange=False):
3103+
manage_xticks=True, autorange=False, zorder=None):
31043104
"""
31053105
Make a box and whisker plot.
31063106
@@ -3113,7 +3113,7 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
31133113
showbox=True, showfliers=True, boxprops=None,
31143114
labels=None, flierprops=None, medianprops=None,
31153115
meanprops=None, capprops=None, whiskerprops=None,
3116-
manage_xticks=True, autorange=False):
3116+
manage_xticks=True, autorange=False, zorder=None):
31173117
31183118
Make a box and whisker plot for each column of ``x`` or each
31193119
vector in sequence ``x``. The box extends from the lower to
@@ -3225,6 +3225,9 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
32253225
``shownotches`` is also True. Otherwise, means will be shown
32263226
as points.
32273227
3228+
zorder : scalar, optional (None)
3229+
Sets the zorder of the boxplot.
3230+
32283231
Other Parameters
32293232
----------------
32303233
The following boolean options toggle the drawing of individual
@@ -3395,15 +3398,15 @@ def _update_dict(dictionary, rc_name, properties):
33953398
medianprops=medianprops, meanprops=meanprops,
33963399
meanline=meanline, showfliers=showfliers,
33973400
capprops=capprops, whiskerprops=whiskerprops,
3398-
manage_xticks=manage_xticks)
3401+
manage_xticks=manage_xticks, zorder=zorder)
33993402
return artists
34003403

34013404
def bxp(self, bxpstats, positions=None, widths=None, vert=True,
34023405
patch_artist=False, shownotches=False, showmeans=False,
34033406
showcaps=True, showbox=True, showfliers=True,
34043407
boxprops=None, whiskerprops=None, flierprops=None,
34053408
medianprops=None, capprops=None, meanprops=None,
3406-
meanline=False, manage_xticks=True):
3409+
meanline=False, manage_xticks=True, zorder=None):
34073410
"""
34083411
Drawing function for box and whisker plots.
34093412
@@ -3414,7 +3417,7 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
34143417
showcaps=True, showbox=True, showfliers=True,
34153418
boxprops=None, whiskerprops=None, flierprops=None,
34163419
medianprops=None, capprops=None, meanprops=None,
3417-
meanline=False, manage_xticks=True):
3420+
meanline=False, manage_xticks=True, zorder=None):
34183421
34193422
Make a box and whisker plot for each column of *x* or each
34203423
vector in sequence *x*. The box extends from the lower to
@@ -3518,6 +3521,9 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
35183521
manage_xticks : bool, default = True
35193522
If the function should adjust the xlim and xtick locations.
35203523
3524+
zorder : scalar, default = None
3525+
The zorder of the resulting boxplot
3526+
35213527
Returns
35223528
-------
35233529
result : dict
@@ -3560,7 +3566,10 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=True,
35603566
# empty list of xticklabels
35613567
datalabels = []
35623568

3563-
zorder = mlines.Line2D.zorder
3569+
# Use default zorder if none specified
3570+
if zorder is None:
3571+
zorder = mlines.Line2D.zorder
3572+
35643573
zdelta = 0.1
35653574
# box properties
35663575
if patch_artist:

lib/matplotlib/tests/test_axes.py

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

20142014

2015+
@cleanup
2016+
def test_boxplot_zorder():
2017+
x = np.arange(10)
2018+
fix, ax = plt.subplots()
2019+
assert ax.boxplot(x)['boxes'][0].get_zorder() == 2
2020+
assert ax.boxplot(x, zorder=10)['boxes'][0].get_zorder() == 10
2021+
2022+
20152023
@cleanup
20162024
def test_boxplot_bad_ci_2():
20172025
x = np.linspace(-7, 7, 140)

0 commit comments

Comments
 (0)