Skip to content

Commit a40a9e9

Browse files
committed
Deprecate parameter orientation of bar() and barh()
1 parent d541b6d commit a40a9e9

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

doc/api/api_changes_3.3/deprecations.rst

+5
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,11 @@ experimental and may change in the future.
531531
These are unused and can be easily reproduced by other date tools.
532532
`.get_epoch` will return Matplotlib's epoch.
533533

534+
Passing ``orientation`` to ``bar()`` and ``barh()``
535+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
536+
This parameter is considered internal. Please use ``bar()`` for vertical bars
537+
and ``barh()`` for horizontal bars.
538+
534539
``axes_grid1.CbarAxes`` attributes
535540
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
536541
The ``cbid`` and ``locator`` attribute are deprecated. Use

lib/matplotlib/axes/_axes.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -2392,7 +2392,14 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
23922392
error_kw.setdefault('ecolor', ecolor)
23932393
error_kw.setdefault('capsize', capsize)
23942394

2395-
orientation = kwargs.pop('orientation', 'vertical')
2395+
if 'orientation' in kwargs:
2396+
orientation = kwargs['orientation']
2397+
cbook.warn_deprecated(
2398+
"3.3", message="passing 'orientation' to bar() is for "
2399+
"internal use only. Please use barh() or bar() "
2400+
"explicitly to define the orientation.")
2401+
else:
2402+
orientation = kwargs.pop('_orientation', 'vertical')
23962403
cbook._check_in_list(['vertical', 'horizontal'],
23972404
orientation=orientation)
23982405
log = kwargs.pop('log', False)
@@ -2630,9 +2637,17 @@ def barh(self, y, width, height=0.8, left=None, *, align="center",
26302637
:doc:`/gallery/lines_bars_and_markers/horizontal_barchart_distribution`
26312638
.
26322639
"""
2633-
kwargs.setdefault('orientation', 'horizontal')
2640+
2641+
if 'orientation' in kwargs:
2642+
orientation = kwargs['orientation']
2643+
cbook.warn_deprecated(
2644+
"3.3", message="passing 'orientation' to barh() is for "
2645+
"internal use only. Please use bar() or barh() "
2646+
"explicitly to define the orientation.")
2647+
else:
2648+
orientation = 'horizontal'
26342649
patches = self.bar(x=left, height=height, width=width, bottom=y,
2635-
align=align, **kwargs)
2650+
align=align, _orientation=orientation, **kwargs)
26362651
return patches
26372652

26382653
@_preprocess_data()

lib/matplotlib/tests/test_axes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5452,7 +5452,7 @@ def test_bar_broadcast_args():
54525452
# Check that a bar chart with a single height for all bars works.
54535453
ax.bar(range(4), 1)
54545454
# Check that a horizontal chart with one width works.
5455-
ax.bar(0, 1, bottom=range(4), width=1, orientation='horizontal')
5455+
ax.barh(0, 1, left=range(4), height=1)
54565456
# Check that edgecolor gets broadcast.
54575457
rect1, rect2 = ax.bar([0, 1], [0, 1], edgecolor=(.1, .2, .3, .4))
54585458
assert rect1.get_edgecolor() == rect2.get_edgecolor() == (.1, .2, .3, .4)

0 commit comments

Comments
 (0)