Skip to content

Commit

Permalink
deprecate boxplot:vertical rcparam
Browse files Browse the repository at this point in the history
  • Loading branch information
saranti committed May 7, 2024
1 parent 07b29f7 commit 3bc3735
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
12 changes: 7 additions & 5 deletions doc/api/next_api_changes/deprecations/28074-TS.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
``boxplot`` and ``bxp`` *vert* parameter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``boxplot`` and ``bxp`` *vert* parameter, and ``boxplot.vertical`` rcparam
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The parameter *vert: bool* has been deprecated on `~.Axes.boxplot` and
`~.Axes.bxp`.
It is replaced by *orientation: {"vertical", "horizontal"}* for API
consistency.
`~.Axes.bxp`. It is replaced by *orientation: {"vertical", "horizontal"}*
for API consistency.

The *boxplot.vertical* rcparam which controlled the orientation of ``boxplot``
is deprecated as the new API does not require its use.
16 changes: 12 additions & 4 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4060,6 +4060,8 @@ def boxplot(self, x, notch=None, sym=None, vert=None,
labels=tick_labels, autorange=autorange)
if notch is None:
notch = mpl.rcParams['boxplot.notch']
if vert is None:
vert = mpl.rcParams['boxplot.vertical']
if patch_artist is None:
patch_artist = mpl.rcParams['boxplot.patchartist']
if meanline is None:
Expand Down Expand Up @@ -4359,17 +4361,23 @@ def merge_kw_rc(subkey, explicit, zdelta=0, usemarker=True):
mean_kw[removed_prop] = ''

# vert and orientation parameters are linked until vert's
# deprecation period expires. If both are selected,
# vert takes precedence.
if vert is not None:
# deprecation period expires. vert only takes precedence and
# raises a deprecation warning if set to False.
if vert is False:
_api.warn_deprecated(
"3.10",
name="vert: bool",
alternative="orientation: {'vertical', 'horizontal'}"
)
orientation = 'vertical' if vert else 'horizontal'
orientation = 'horizontal'
_api.check_in_list(['horizontal', 'vertical'], orientation=orientation)

if not mpl.rcParams['boxplot.vertical']:
_api.warn_deprecated(
"3.10",
name='boxplot.vertical', obj_type="rcparam"
)

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

Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ boxplot.showbox: True
boxplot.showcaps: True
boxplot.showfliers: True
boxplot.showmeans: False
boxplot.vertical: True
boxplot.whiskerprops.color: b
boxplot.whiskerprops.linestyle: --
boxplot.whiskerprops.linewidth: 1.0
Expand Down
10 changes: 6 additions & 4 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9061,13 +9061,15 @@ def test_boxplot_orientation(fig_test, fig_ref):

plt.close()

# Deprecation of `vert: bool` keyword
# Deprecation of `vert: bool` keyword and
# 'boxplot.vertical' rcparam.
with pytest.warns(mpl.MatplotlibDeprecationWarning,
match='vert: bool was deprecated in Matplotlib 3.10'):
match='was deprecated in Matplotlib 3.10'):
# Compare images between a figure that
# uses vert and one that uses orientation.
ax_ref = fig_ref.subplots()
ax_ref.boxplot(all_data, vert=False)
with mpl.rc_context({'boxplot.vertical': False}):
ax_ref = fig_ref.subplots()
ax_ref.boxplot(all_data)

ax_test = fig_test.subplots()
ax_test.boxplot(all_data, orientation='horizontal')

0 comments on commit 3bc3735

Please sign in to comment.