Skip to content

Commit ce315ff

Browse files
committed
Merge remote-tracking branch 'matplotlib/v2.x'
2 parents 77ad3ef + 8428821 commit ce315ff

File tree

5 files changed

+80
-24
lines changed

5 files changed

+80
-24
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,9 +1981,12 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs):
19811981
19821982
.. plot:: mpl_examples/pylab_examples/bar_stacked.py
19831983
"""
1984+
kwargs = cbook.normalize_kwargs(kwargs, mpatches._patch_alias_map)
19841985
if not self._hold:
19851986
self.cla()
19861987
color = kwargs.pop('color', None)
1988+
if color is None:
1989+
color = self._get_patches_for_fill.get_next_color()
19871990
edgecolor = kwargs.pop('edgecolor', None)
19881991
linewidth = kwargs.pop('linewidth', None)
19891992

@@ -2063,14 +2066,11 @@ def make_iterable(x):
20632066
if len(linewidth) < nbars:
20642067
linewidth *= nbars
20652068

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

20752075
if edgecolor is None:
20762076
edgecolor = [None] * nbars
@@ -2417,34 +2417,71 @@ def stem(self, *args, **kwargs):
24172417

24182418
# Popping some defaults
24192419
try:
2420-
linefmt = kwargs.pop('linefmt', args[0])
2421-
except IndexError:
2422-
linefmt = kwargs.pop('linefmt', 'b-')
2420+
linefmt = kwargs['linefmt']
2421+
except KeyError:
2422+
try:
2423+
linefmt = args[0]
2424+
except IndexError:
2425+
linecolor = 'C0'
2426+
linemarker = 'None'
2427+
linestyle = '-'
2428+
else:
2429+
linestyle, linemarker, linecolor = \
2430+
_process_plot_format(linefmt)
2431+
else:
2432+
linestyle, linemarker, linecolor = _process_plot_format(linefmt)
24232433
try:
2424-
markerfmt = kwargs.pop('markerfmt', args[1])
2425-
except IndexError:
2426-
markerfmt = kwargs.pop('markerfmt', 'bo')
2434+
markerfmt = kwargs['markerfmt']
2435+
except KeyError:
2436+
try:
2437+
markerfmt = args[1]
2438+
except IndexError:
2439+
markercolor = 'C0'
2440+
markermarker = 'o'
2441+
markerstyle = 'None'
2442+
else:
2443+
markerstyle, markermarker, markercolor = \
2444+
_process_plot_format(markerfmt)
2445+
else:
2446+
markerstyle, markermarker, markercolor = \
2447+
_process_plot_format(markerfmt)
24272448
try:
2428-
basefmt = kwargs.pop('basefmt', args[2])
2429-
except IndexError:
2430-
basefmt = kwargs.pop('basefmt', 'r-')
2449+
basefmt = kwargs['basefmt']
2450+
except KeyError:
2451+
try:
2452+
basefmt = args[2]
2453+
except IndexError:
2454+
if rcParams['_internal.classic_mode']:
2455+
basecolor = 'C2'
2456+
else:
2457+
basecolor = 'C3'
2458+
basemarker = 'None'
2459+
basestyle = '-'
2460+
else:
2461+
basestyle, basemarker, basecolor = \
2462+
_process_plot_format(basefmt)
2463+
else:
2464+
basestyle, basemarker, basecolor = _process_plot_format(basefmt)
24312465

24322466
bottom = kwargs.pop('bottom', None)
24332467
label = kwargs.pop('label', None)
24342468

2435-
markerline, = self.plot(x, y, markerfmt, label="_nolegend_")
2469+
markerline, = self.plot(x, y, color=markercolor, linestyle=markerstyle,
2470+
marker=markermarker, label="_nolegend_")
24362471

24372472
if bottom is None:
24382473
bottom = 0
24392474

24402475
stemlines = []
24412476
for thisx, thisy in zip(x, y):
2442-
l, = self.plot([thisx, thisx], [bottom, thisy], linefmt,
2443-
label="_nolegend_")
2477+
l, = self.plot([thisx, thisx], [bottom, thisy],
2478+
color=linecolor, linestyle=linestyle,
2479+
marker=linemarker, label="_nolegend_")
24442480
stemlines.append(l)
24452481

24462482
baseline, = self.plot([np.amin(x), np.amax(x)], [bottom, bottom],
2447-
basefmt, label="_nolegend_")
2483+
color=basecolor, linestyle=basestyle,
2484+
marker=basemarker, label="_nolegend_")
24482485

24492486
self.hold(remember_hold)
24502487

lib/matplotlib/patches.py

Lines changed: 8 additions & 0 deletions
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/rcsetup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ def validate_animation_writer_path(p):
965965
'boxplot.medianprops.linewidth': [1.0, validate_float],
966966
'boxplot.medianprops.linestyle': ['-', six.text_type],
967967

968-
'boxplot.meanprops.color': ['r', validate_color],
968+
'boxplot.meanprops.color': ['C3', validate_color],
969969
'boxplot.meanprops.linewidth': [1.0, validate_float],
970970
'boxplot.meanprops.linestyle': ['-', six.text_type],
971971

lib/matplotlib/tests/test_axes.py

Lines changed: 12 additions & 1 deletion
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
@@ -4494,6 +4494,17 @@ def test_large_offset():
44944494
fig.canvas.draw()
44954495

44964496

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

lib/matplotlib/tests/test_bbox_tight.py

Lines changed: 1 addition & 1 deletion
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)