Skip to content

Commit 8130ea9

Browse files
authored
Merge pull request #11640 from timhoffm/fix-ax-bar-color-none-alpha
Fix barplot color if none and alpha is set
2 parents 2486f89 + dd52123 commit 8130ea9

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,14 +2005,14 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
20052005
linewidth = itertools.cycle(np.atleast_1d(linewidth))
20062006
color = itertools.chain(itertools.cycle(mcolors.to_rgba_array(color)),
20072007
# Fallback if color == "none".
2008-
itertools.repeat([0, 0, 0, 0]))
2008+
itertools.repeat('none'))
20092009
if edgecolor is None:
20102010
edgecolor = itertools.repeat(None)
20112011
else:
20122012
edgecolor = itertools.chain(
20132013
itertools.cycle(mcolors.to_rgba_array(edgecolor)),
20142014
# Fallback if edgecolor == "none".
2015-
itertools.repeat([0, 0, 0, 0]))
2015+
itertools.repeat('none'))
20162016

20172017
# We will now resolve the alignment and really have
20182018
# left, bottom, width, height vectors

lib/matplotlib/tests/test_axes.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,22 @@ def test_bar_tick_label_multiple_old_alignment():
14561456
align='center')
14571457

14581458

1459+
def test_bar_color_none_alpha():
1460+
ax = plt.gca()
1461+
rects = ax.bar([1, 2], [2, 4], alpha=0.3, color='none', edgecolor='r')
1462+
for rect in rects:
1463+
assert rect.get_facecolor() == (0, 0, 0, 0)
1464+
assert rect.get_edgecolor() == (1, 0, 0, 0.3)
1465+
1466+
1467+
def test_bar_edgecolor_none_alpha():
1468+
ax = plt.gca()
1469+
rects = ax.bar([1, 2], [2, 4], alpha=0.3, color='r', edgecolor='none')
1470+
for rect in rects:
1471+
assert rect.get_facecolor() == (1, 0, 0, 0.3)
1472+
assert rect.get_edgecolor() == (0, 0, 0, 0)
1473+
1474+
14591475
@image_comparison(baseline_images=['barh_tick_label'],
14601476
extensions=['png'])
14611477
def test_barh_tick_label():

0 commit comments

Comments
 (0)