8000 Allow scalar height specification in plt.bar() · matplotlib/matplotlib@febc629 · GitHub
[go: up one dir, main page]

Skip to content

Commit febc629

Browse files
committed
Allow scalar height specification in plt.bar()
1 parent 159f36e commit febc629

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,8 +1876,8 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
18761876
left : sequence of scalars
18771877
the x coordinates of the left sides of the bars
18781878
1879-
height : sequence of scalars
1880-
the heights of the bars
1879+
height : scalar or sequence of scalars
1880+
the height(s) of the bars
18811881
18821882
width : scalar or array-like, optional
18831883
the width(s) of the bars
@@ -2025,6 +2025,8 @@ def make_iterable(x):
20252025
bottom = [0]
20262026

20272027
nbars = len(left)
2028+
if len(height) == 1:
2029+
height *= nbars
20282030
if len(width) == 1:
20292031
width *= nbars
20302032
if len(bottom) == 1:
@@ -2047,6 +2049,8 @@ def make_iterable(x):
20472049
left *= nbars
20482050
if len(height) == 1:
20492051
height *= nbars
2052+
if len(width) == 1:
2053+
width *= nbars
20502054

20512055
tick_label_axis = self.yaxis
20522056
tick_label_position = bottom
@@ -2077,7 +2081,7 @@ def make_iterable(x):
20772081
"be length %d or scalar" % nbars)
20782082
if len(height) != nbars:
20792083
raise ValueError("incompatible sizes: argument 'height' "
2080-
"must be length %d or scalar" % nbars)
2084+
"must be length %d or scalar" % nbars)
20812085
if len(width) != nbars:
20822086
raise ValueError("incompatible sizes: argument 'width' "
20832087
"must be length %d or scalar" % nbars)

0 commit comments

Comments
 (0)
0