Skip to content

Commit dd2eda9

Browse files
committed
simplify code
1 parent 9cebb95 commit dd2eda9

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3819,15 +3819,16 @@ def apply_mask(arrays, mask):
38193819
@_api.make_keyword_only("3.9", "notch")
38203820
@_preprocess_data()
38213821
@_api.rename_parameter("3.9", "labels", "tick_labels")
3822-
def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
3823-
positions=None, widths=None, patch_artist=None,
3824-
bootstrap=None, usermedians=None, conf_intervals=None,
3822+
def boxplot(self, x, notch=None, sym=None, vert=None,
3823+
orientation='vertical', whis=None, positions=None,
3824+
widths=None, patch_artist=None, bootstrap=None,
3825+
usermedians=None, conf_intervals=None,
38253826
meanline=None, showmeans=None, showcaps=None,
38263827
showbox=None, showfliers=None, boxprops=None,
38273828
tick_labels=None, flierprops=None, medianprops=None,
38283829
meanprops=None, capprops=None, whiskerprops=None,
38293830
manage_ticks=True, autorange=False, zorder=None,
3830-
capwidths=None, label=None, orientation=None):
3831+
capwidths=None, label=None):
38313832
"""
38323833
Draw a box and whisker plot.
38333834
@@ -3887,6 +3888,12 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
38873888
If True, plots the boxes vertically.
38883889
If False, plots the boxes horizontally.
38893890
3891+
orientation : {'vertical', 'horizontal'}, default: 'vertical'
3892+
If 'horizontal', plots the boxes horizontally.
3893+
Otherwise, plots the boxes vertically.
3894+
3895+
.. versionadded:: 3.10
3896+
38903897
whis : float or (float, float), default: 1.5
38913898
The position of the whiskers.
38923899
@@ -3972,12 +3979,6 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
39723979
zorder : float, default: ``Line2D.zorder = 2``
39733980
The zorder of the boxplot.
39743981
3975-
orientation : {'vertical', 'horizontal'}, default: 'vertical'
3976-
If 'horizontal', plots the boxes horizontally.
3977-
Otherwise, plots the boxes vertically.
3978-
3979-
.. versionadded:: 3.10
3980-
39813982
Returns
39823983
-------
39833984
dict
@@ -4164,12 +4165,12 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
41644165

41654166
@_api.make_keyword_only("3.9", "widths")
41664167
def bxp(self, bxpstats, positions=None, widths=None, vert=None,
4167-
patch_artist=False, shownotches=False, showmeans=False,
4168-
showcaps=True, showbox=True, showfliers=True,
4168+
orientation=None, patch_artist=False, shownotches=False,
4169+
showmeans=False, showcaps=True, showbox=True, showfliers=True,
41694170
boxprops=None, whiskerprops=None, flierprops=None,
41704171
medianprops=None, capprops=None, meanprops=None,
41714172
meanline=False, manage_ticks=True, zorder=None,
4172-
capwidths=None, label=None, orientation=None):
4173+
capwidths=None, label=None):
41734174
"""
41744175
Draw a box and whisker plot from pre-computed statistics.
41754176
@@ -4234,6 +4235,12 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=None,
42344235
If True, plots the boxes vertically.
42354236
If False, plots the boxes horizontally.
42364237
4238+
orientation : {'vertical', 'horizontal'}, default: 'vertical'
4239+
If 'horizontal', plots the boxes horizontally.
4240+
Otherwise, plots the boxes vertically.
4241+
4242+
.. versionadded:: 3.10
4243+
42374244
patch_artist : bool, default: False
42384245
If `False` produces boxes with the `.Line2D` artist.
42394246
If `True` produces boxes with the `~matplotlib.patches.Patch` artist.
@@ -4275,12 +4282,6 @@ def bxp(self, bxpstats, positions=None, widths=None, vert=None,
42754282
zorder : float, default: ``Line2D.zorder = 2``
42764283
The zorder of the resulting boxplot.
42774284
4278-
orientation : {'vertical', 'horizontal'}, default: 'vertical'
4279-
If 'horizontal', plots the boxes horizontally.
4280-
Otherwise, plots the boxes vertically.
4281-
4282-
.. versionadded:: 3.10
4283-
42844285
Returns
42854286
-------
42864287
dict
@@ -4357,23 +4358,17 @@ def merge_kw_rc(subkey, explicit, zdelta=0, usemarker=True):
43574358
if meanprops is None or removed_prop not in meanprops:
43584359
mean_kw[removed_prop] = ''
43594360

4361+
# vert and orientation parameters are linked until vert's
4362+
# deprecation period expires. If both are selected,
4363+
# vert takes precedence.
43604364
if vert is not None:
43614365
_api.warn_deprecated(
43624366
"3.10",
43634367
name="vert: bool",
43644368
alternative="orientation: {'vertical', 'horizontal'}"
4365-
)
4366-
4367-
# vert and orientation parameters are linked until vert's
4368-
# deprecation period expires. If both are selected,
4369-
# vert takes precedence.
4370-
if vert or vert is None and orientation is None:
4371-
orientation = 'vertical'
4372-
elif vert is False:
4373-
orientation = 'horizontal'
4374-
4375-
if orientation is not None:
4376-
_api.check_in_list(['horizontal', 'vertical'], orientation=orientation)
4369+
)
4370+
orientation = 'vertical' if vert else 'horizontal'
4371+
_api.check_in_list(['horizontal', 'vertical'], orientation=orientation)
43774372

43784373
# vertical or horizontal plot?
43794374
maybe_swap = slice(None) if orientation == 'vertical' else slice(None, None, -1)

lib/matplotlib/axes/_axes.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ class Axes(_AxesBase):
350350
notch: bool | None = ...,
351351
sym: str | None = ...,
352352
vert: bool | None = ...,
353+
orientation: Literal["vertical", "horizontal"] = ...,
353354
whis: float | tuple[float, float] | None = ...,
354355
positions: ArrayLike | None = ...,
355356
widths: float | ArrayLike | None = ...,
@@ -374,7 +375,6 @@ class Axes(_AxesBase):
374375
zorder: float | None = ...,
375376
capwidths: float | ArrayLike | None = ...,
376377
label: Sequence[str] | None = ...,
377-
orientation: Literal["vertical", "horizontal"] | None = ...,
378378
data=...,
379379
) -> dict[str, Any]: ...
380380
def bxp(
@@ -384,6 +384,7 @@ class Axes(_AxesBase):
384384
*,
385385
widths: float | ArrayLike | None = ...,
386386
vert: bool | None = ...,
387+
orientation: Literal["vertical", "horizontal"] | None = ...,
387388
patch_artist: bool = ...,
388389
shownotches: bool = ...,
389390
showmeans: bool = ...,
@@ -401,7 +402,6 @@ class Axes(_AxesBase):
401402
zorder: float | None = ...,
402403
capwidths: float | ArrayLike | None = ...,
403404
label: Sequence[str] | None = ...,
404-
orientation: Literal["vertical", "horizontal"] | None = ...,
405405
) -> dict[str, Any]: ...
406406
def scatter(
407407
self,

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,6 +2918,7 @@ def boxplot(
29182918
notch: bool | None = None,
29192919
sym: str | None = None,
29202920
vert: bool | None = None,
2921+
orientation: Literal["vertical", "horizontal"] = "vertical",
29212922
whis: float | tuple[float, float] | None = None,
29222923
positions: ArrayLike | None = None,
29232924
widths: float | ArrayLike | None = None,
@@ -2942,7 +2943,6 @@ def boxplot(
29422943
zorder: float | None = None,
29432944
capwidths: float | ArrayLike | None = None,
29442945
label: Sequence[str] | None = None,
2945-
orientation: Literal["vertical", "horizontal"] | None = None,
29462946
*,
29472947
data=None,
29482948
) -> dict[str, Any]:
@@ -2951,6 +2951,7 @@ def boxplot(
29512951
notch=notch,
29522952
sym=sym,
29532953
vert=vert,
2954+
orientation=orientation,
29542955
whis=whis,
29552956
positions=positions,
29562957
widths=widths,
@@ -2975,7 +2976,6 @@ def boxplot(
29752976
zorder=zorder,
29762977
capwidths=capwidths,
29772978
label=label,
2978-
orientation=orientation,
29792979
**({"data": data} if data is not None else {}),
29802980
)
29812981

0 commit comments

Comments
 (0)