Skip to content

API: bar now color cycles #6364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1980,9 +1980,12 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):

.. plot:: mpl_examples/pylab_examples/bar_stacked.py
"""
kwargs = cbook.normalize_kwargs(kwargs, mpatches._patch_alias_map)
if not self._hold:
self.cla()
color = kwargs.pop('color', None)
if color is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are going to need to do the keyword normalization prior to this step. How do we want to coordinate this with the normalization PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you touch bar in that PR?

The kwarg normalization should probably be done via a decorator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bar is not touched in that PR. Only plot() and fill(), however, that does indirectly impact a lot of other plotting functions since they serve as the basis for many others. I don't think bar() calls fill(), though.

As for normalizing via kwargs, I'd agree, in general. We would need to be careful on any collisions with other kwargs, and if there are any organically-grown alias-handling logic that would need to be cleaned up as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still needs kwarg normalization

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done but used a different set of aliases. Passing in c currently does not work, no reason to let it start working.

color = self._get_patches_for_fill.get_next_color()
edgecolor = kwargs.pop('edgecolor', None)
linewidth = kwargs.pop('linewidth', None)

Expand Down Expand Up @@ -2062,14 +2065,11 @@ def make_iterable(x):
if len(linewidth) < nbars:
linewidth *= nbars

if color is None:
color = [None] * nbars
else:
color = list(mcolors.to_rgba_array(color))
if len(color) == 0: # until to_rgba_array is changed
color = [[0, 0, 0, 0]]
if len(color) < nbars:
color *= nbars
color = list(mcolors.to_rgba_array(color))
if len(color) == 0: # until to_rgba_array is changed
color = [[0, 0, 0, 0]]
if len(color) < nbars:
color *= nbars

if edgecolor is None:
edgecolor = [None] * nbars
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@

""")

_patch_alias_map = {
'antialiased': ['aa'],
'edgecolor': ['ec'],
'facecolor': ['fc'],
'linewidth': ['lw'],
'linestyle': ['ls']
}


class Patch(artist.Artist):
"""
Expand Down
13 changes: 12 additions & 1 deletion lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from numpy.testing import assert_allclose, assert_array_equal
import warnings
from matplotlib.cbook import IgnoredKeywordWarning

import matplotlib.colors as mcolors

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


def test_bar_color_cycle():
ccov = mcolors.colorConverter.to_rgb
fig, ax = plt.subplots()
for j in range(5):
ln, = ax.plot(range(3))
brs = ax.bar(range(3), range(3))
for br in brs:
print(ln.get_color(), br.get_facecolor())
assert ccov(ln.get_color()) == ccov(br.get_facecolor())


if __name__ == '__main__':
import nose
import sys
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_bbox_tight.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_bbox_inches_tight():
# the bottom values for stacked bar chart
fig, ax = plt.subplots(1, 1)
for row in xrange(rows):
plt.bar(ind, data[row], width, bottom=yoff)
ax.bar(ind, data[row], width, bottom=yoff, color='b')
yoff = yoff + data[row]
cellText.append([''])
plt.xticks([])
Expand Down