Skip to content

Commit d063820

Browse files
committed
Merge pull request #6364 from tacaswell/API_bar_color_cycles
API: bar now color cycles
2 parents 40bbe61 + 5e55680 commit d063820

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

lib/matplotlib/axes/_axes.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1980,9 +1980,12 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
19801980
19811981
.. plot:: mpl_examples/pylab_examples/bar_stacked.py
19821982
"""
1983+
kwargs = cbook.normalize_kwargs(kwargs, mpatches._patch_alias_map)
19831984
if not self._hold:
19841985
self.cla()
19851986
color = kwargs.pop('color', None)
1987+
if color is None:
1988+
color = self._get_patches_for_fill.get_next_color()
19861989
edgecolor = kwargs.pop('edgecolor', None)
19871990
linewidth = kwargs.pop('linewidth', None)
19881991

@@ -2062,14 +2065,11 @@ def make_iterable(x):
20622065
if len(linewidth) < nbars:
20632066
linewidth *= nbars
20642067

2065-
if color is None:
2066-
color = [None] * nbars
2067-
else:
2068-
color = list(mcolors.to_rgba_array(color))
2069-
if len(color) == 0: # until to_rgba_array is changed
2070-
color = [[0, 0, 0, 0]]
2071-
if len(color) < nbars:
2072-
color *= nbars
2068+
color = list(mcolors.to_rgba_array(color))
2069+
if len(color) == 0: # until to_rgba_array is changed
2070+
color = [[0, 0, 0, 0]]
2071+
if len(color) < nbars:
2072+
color *= nbars
20732073

20742074
if edgecolor is None:
20752075
edgecolor = [None] * nbars

lib/matplotlib/patches.py

+8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@
5555
5656
""")
5757

58+
_patch_alias_map = {
59+
'antialiased': ['aa'],
60+
'edgecolor': ['ec'],
61+
'facecolor': ['fc'],
62+
'linewidth': ['lw'],
63+
'linestyle': ['ls']
64+
}
65+
5866

5967
class Patch(artist.Artist):
6068
"""

lib/matplotlib/tests/test_axes.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from numpy.testing import assert_allclose, assert_array_equal
3030
import warnings
3131
from matplotlib.cbook import IgnoredKeywordWarning
32-
32+
import matplotlib.colors as mcolors
3333

3434
# Note: Some test cases are run twice: once normally and once with labeled data
3535
# These two must be defined in the same test function or need to have
@@ -4492,6 +4492,17 @@ def test_large_offset():
44924492
fig.canvas.draw()
44934493

44944494

4495+
def test_bar_color_cycle():
4496+
ccov = mcolors.colorConverter.to_rgb
4497+
fig, ax = plt.subplots()
4498+
for j in range(5):
4499+
ln, = ax.plot(range(3))
4500+
brs = ax.bar(range(3), range(3))
4501+
for br in brs:
4502+
print(ln.get_color(), br.get_facecolor())
4503+
assert ccov(ln.get_color()) == ccov(br.get_facecolor())
4504+
4505+
44954506
if __name__ == '__main__':
44964507
import nose
44974508
import sys

lib/matplotlib/tests/test_bbox_tight.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_bbox_inches_tight():
3434
# the bottom values for stacked bar chart
3535
fig, ax = plt.subplots(1, 1)
3636
for row in xrange(rows):
37-
plt.bar(ind, data[row], width, bottom=yoff)
37+
ax.bar(ind, data[row], width, bottom=yoff, color='b')
3838
yoff = yoff + data[row]
3939
cellText.append([''])
4040
plt.xticks([])

0 commit comments

Comments
 (0)