Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8d7dfcc

Browse files
committed
Fix bug in color handling by bar, found by Thomas Guettler
svn path=/trunk/matplotlib/; revision=6140
1 parent 173b8bc commit 8d7dfcc

1 file changed

Lines changed: 18 additions & 22 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,25 +3822,22 @@ def make_iterable(x):
38223822
#width = np.asarray(width)
38233823
#bottom = np.asarray(bottom)
38243824

3825-
if len(linewidth) == 1: linewidth = linewidth * nbars
3826-
3827-
# if color looks like a color string, an RGB tuple or a
3828-
# scalar, then repeat it by nbars
3829-
if (is_string_like(color) or
3830-
(iterable(color) and
3831-
len(color) in (3, 4) and
3832-
nbars != len(color)) or
3833-
not iterable(color)):
3834-
color = [color]*nbars
3835-
3836-
# if edgecolor looks like a color string, an RGB tuple or a
3837-
# scalar, then repeat it by nbars
3838-
if (is_string_like(edgecolor) or
3839-
(iterable(edgecolor) and
3840-
len(edgecolor) in (3, 4) and
3841-
nbars != len(edgecolor)) or
3842-
not iterable(edgecolor)):
3843-
edgecolor = [edgecolor]*nbars
3825+
if len(linewidth) < nbars:
3826+
linewidth *= nbars
3827+
3828+
if color is None:
3829+
color = [None] * nbars
3830+
else:
3831+
color = list(mcolors.colorConverter.to_rgba_array(color))
3832+
if len(color) < nbars:
3833+
color *= nbars
3834+
3835+
if edgecolor is None:
3836+
edgecolor = [None] * nbars
3837+
else:
3838+
edgecolor = list(mcolors.colorConverter.to_rgba_array(edgecolor))
3839+
if len(edgecolor) < nbars:
3840+
edgecolor *= nbars
38443841

38453842
if yerr is not None:
38463843
if not iterable(yerr):
@@ -3850,13 +3847,12 @@ def make_iterable(x):
38503847
if not iterable(xerr):
38513848
xerr = [xerr]*nbars
38523849

3850+
# FIXME: convert the following to proper input validation
3851+
# raising ValueError; don't use assert for this.
38533852
assert len(left)==nbars, "argument 'left' must be %d or scalar" % nbars
38543853
assert len(height)==nbars, "argument 'height' must be %d or scalar" % nbars
38553854
assert len(width)==nbars, "argument 'width' must be %d or scalar" % nbars
38563855
assert len(bottom)==nbars, "argument 'bottom' must be %d or scalar" % nbars
3857-
assert len(color)==nbars, "argument 'color' must be %d or scalar" % nbars
3858-
assert len(edgecolor)==nbars, "argument 'edgecolor' must be %d or scalar" % nbars
3859-
assert len(linewidth)==nbars, "argument 'linewidth' must be %d or scalar" % nbars
38603856

38613857
if yerr is not None and len(yerr)!=nbars:
38623858
raise ValueError("bar() argument 'yerr' must be len(%s) or scalar" % nbars)

0 commit comments

Comments
 (0)