Skip to content

Deprecate parameter orientation of bar() and barh() #17322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/api_changes_3.3/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ experimental and may change in the future.
These are unused and can be easily reproduced by other date tools.
`.get_epoch` will return Matplotlib's epoch.

Passing ``orientation`` to ``bar()`` and ``barh()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This parameter is considered internal. Please use ``bar()`` for vertical bars
and ``barh()`` for horizontal bars.

``axes_grid1.CbarAxes`` attributes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``cbid`` and ``locator`` attribute are deprecated. Use
Expand Down
21 changes: 18 additions & 3 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2392,7 +2392,14 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
error_kw.setdefault('ecolor', ecolor)
error_kw.setdefault('capsize', capsize)

orientation = kwargs.pop('orientation', 'vertical')
if 'orientation' in kwargs:
orientation = kwargs['orientation']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are going to rename we should add a check that we don't get both.

cbook.warn_deprecated(
"3.3", message="passing 'orientation' to bar() is for "
"internal use only. Please use barh() or bar() "
"explicitly to define the orientation.")
else:
orientation = kwargs.pop('_orientation', 'vertical')
cbook._check_in_list(['vertical', 'horizontal'],
orientation=orientation)
log = kwargs.pop('log', False)
Expand Down Expand Up @@ -2630,9 +2637,17 @@ def barh(self, y, width, height=0.8, left=None, *, align="center",
:doc:`/gallery/lines_bars_and_markers/horizontal_barchart_distribution`
.
"""
kwargs.setdefault('orientation', 'horizontal')

if 'orientation' in kwargs:
orientation = kwargs['orientation']
cbook.warn_deprecated(
"3.3", message="passing 'orientation' to barh() is for "
"internal use only. Please use bar() or barh() "
"explicitly to define the orientation.")
else:
orientation = 'horizontal'
patches = self.bar(x=left, height=height, width=width, bottom=y,
align=align, **kwargs)
align=align, _orientation=orientation, **kwargs)
return patches

@_preprocess_data()
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5452,7 +5452,7 @@ def test_bar_broadcast_args():
# Check that a bar chart with a single height for all bars works.
ax.bar(range(4), 1)
# Check that a horizontal chart with one width works.
ax.bar(0, 1, bottom=range(4), width=1, orientation='horizontal')
ax.barh(0, 1, left=range(4), height=1)
# Check that edgecolor gets broadcast.
rect1, rect2 = ax.bar([0, 1], [0, 1], edgecolor=(.1, .2, .3, .4))
assert rect1.get_edgecolor() == rect2.get_edgecolor() == (.1, .2, .3, .4)
Expand Down