Skip to content

Commit 1627e8e

Browse files
author
Umair Idris
committed
Use enumerate and np.arange instead of range. Raise error if bottom (bar) or left (barh) is list of strings
1 parent e2f9aaa commit 1627e8e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,10 +1946,13 @@ def make_iterable(x):
19461946
if len(bottom) == 1:
19471947
bottom *= nbars
19481948
if nbars and cbook.is_sequence_of_strings(left):
1949-
ticks_loc = [i + width[i]/2 for i in range(nbars)]
1949+
ticks_loc = [i + w/2 for i, w in enumerate(width)]
19501950
self.xaxis.set_ticks(ticks_loc)
19511951
self.xaxis.set_ticklabels(left)
1952-
left = range(nbars)
1952+
left = np.arange(nbars)
1953+
if nbars and cbook.is_sequence_of_strings(bottom):
1954+
raise ValueError('bottom must be scalar or sequence of scalar '
1955+
'for vertical bar')
19531956
elif orientation == 'horizontal':
19541957
self._process_unit_info(xdata=width, ydata=bottom, kwargs=kwargs)
19551958
if log:
@@ -1966,10 +1969,13 @@ def make_iterable(x):
19661969
if len(height) == 1:
19671970
height *= nbars
19681971
if nbars and cbook.is_sequence_of_strings(bottom):
1969-
ticks_loc = [i + height[i]/2 for i in range(nbars)]
1972+
ticks_loc = [i + h/2 for i, h in enumerate(height)]
19701973
self.yaxis.set_ticks(ticks_loc)
19711974
self.yaxis.set_ticklabels(bottom)
1972-
bottom = range(nbars)
1975+
bottom = np.arange(nbars)
1976+
if nbars and cbook.is_sequence_of_strings(left):
1977+
raise ValueError('left must be scalar or sequence of scalar '
1978+
'for horizontal bar')
19731979
else:
19741980
raise ValueError('invalid orientation: %s' % orientation)
19751981

0 commit comments

Comments
 (0)