diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 9f3bc1b9fe83..dab494a350ab 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -1876,8 +1876,8 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs): left : sequence of scalars the x coordinates of the left sides of the bars - height : sequence of scalars - the heights of the bars + height : scalar or sequence of scalars + the height(s) of the bars width : scalar or array-like, optional the width(s) of the bars @@ -2025,8 +2025,6 @@ def make_iterable(x): bottom = [0] nbars = len(left) - if len(width) == 1: - width *= nbars if len(bottom) == 1: bottom *= nbars @@ -2045,14 +2043,16 @@ def make_iterable(x): nbars = len(bottom) if len(left) == 1: left *= nbars - if len(height) == 1: - height *= nbars tick_label_axis = self.yaxis tick_label_position = bottom else: raise ValueError('invalid orientation: %s' % orientation) + if len(height) == 1: + height *= nbars + if len(width) == 1: + width *= nbars if len(linewidth) < nbars: linewidth *= nbars @@ -2077,7 +2077,7 @@ def make_iterable(x): "be length %d or scalar" % nbars) if len(height) != nbars: raise ValueError("incompatible sizes: argument 'height' " - "must be length %d or scalar" % nbars) + "must be length %d or scalar" % nbars) if len(width) != nbars: raise ValueError("incompatible sizes: argument 'width' " "must be length %d or scalar" % nbars) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index dde3c5a806ef..b82abff10a3e 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4877,3 +4877,12 @@ def test_scatter_color_masking(): def test_eventplot_legend(): plt.eventplot([1.0], label='Label') plt.legend() + + +@cleanup +def test_bar_single_height(): + fig, ax = plt.subplots() + # 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')