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

Skip to content

Remove support for bar(left=...) (as opposed to bar(x=...)). #11096

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 1 commit into from
Apr 23, 2018
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
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/2018-04-20-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``bar``/``barh`` no longer accepts ``left``/``bottom`` as first named argument
``````````````````````````````````````````````````````````````````````````````

These arguments were renamed in 2.0 to ``x``/``y`` following the change of the
default alignment from ``edge`` to ``center``.
96 changes: 13 additions & 83 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1814,25 +1814,19 @@ def step(self, x, y, *args, **kwargs):
replace_all_args=True
)
@docstring.dedent_interpd
def bar(self, *args, **kwargs):
def bar(self, x, height, width=0.8, bottom=None, *, align="center",
**kwargs):
r"""
Make a bar plot.

Call signatures::

bar(x, height, *, align='center', **kwargs)
bar(x, height, width, *, align='center', **kwargs)
bar(x, height, width, bottom, *, align='center', **kwargs)

The bars are positioned at *x* with the given *align* ment. Their
The bars are positioned at *x* with the given *align*\ment. Their
dimensions are given by *width* and *height*. The vertical baseline
is *bottom* (default 0).

Each of *x*, *height*, *width*, and *bottom* may either be a scalar
applying to all bars, or it may be a sequence of length N providing a
separate value for each bar.


Parameters
----------
x : sequence of scalars
Expand Down Expand Up @@ -1927,55 +1921,22 @@ def bar(self, *args, **kwargs):

"""
kwargs = cbook.normalize_kwargs(kwargs, mpatches.Patch._alias_map)
# this is using the lambdas to do the arg/kwarg unpacking rather
# than trying to re-implement all of that logic our selves.
matchers = [
(lambda x, height, width=0.8, bottom=None, **kwargs:
(False, x, height, width, bottom, kwargs)),
(lambda left, height, width=0.8, bottom=None, **kwargs:
(True, left, height, width, bottom, kwargs)),
]
exps = []
for matcher in matchers:
try:
dp, x, height, width, y, kwargs = matcher(*args, **kwargs)
except TypeError as e:
# This can only come from a no-match as there is
# no other logic in the matchers.
exps.append(e)
else:
break
else:
raise exps[0]
# if we matched the second-case, then the user passed in
# left=val as a kwarg which we want to deprecate
if dp:
warnings.warn(
"The *left* kwarg to `bar` is deprecated use *x* instead. "
"Support for *left* will be removed in Matplotlib 3.0",
mplDeprecation, stacklevel=2)
color = kwargs.pop('color', None)
if color is None:
color = self._get_patches_for_fill.get_next_color()
edgecolor = kwargs.pop('edgecolor', None)
linewidth = kwargs.pop('linewidth', None)

# Because xerr and yerr will be passed to errorbar,
# most dimension checking and processing will be left
# to the errorbar method.
# Because xerr and yerr will be passed to errorbar, most dimension
# checking and processing will be left to the errorbar method.
xerr = kwargs.pop('xerr', None)
yerr = kwargs.pop('yerr', None)
error_kw = kwargs.pop('error_kw', dict())
error_kw = kwargs.pop('error_kw', {})
ecolor = kwargs.pop('ecolor', 'k')
capsize = kwargs.pop('capsize', rcParams["errorbar.capsize"])
error_kw.setdefault('ecolor', ecolor)
error_kw.setdefault('capsize', capsize)

if rcParams['_internal.classic_mode']:
align = kwargs.pop('align', 'edge')
else:
align = kwargs.pop('align', 'center')

orientation = kwargs.pop('orientation', 'vertical')
log = kwargs.pop('log', False)
label = kwargs.pop('label', '')
Expand All @@ -1984,8 +1945,9 @@ def bar(self, *args, **kwargs):
adjust_ylim = False
adjust_xlim = False

y = bottom # Matches barh call signature.
if orientation == 'vertical':
if y is None:
if bottom is None:
if self.get_yscale() == 'log':
adjust_ylim = True
y = 0
Expand Down Expand Up @@ -2126,25 +2088,19 @@ def bar(self, *args, **kwargs):
return bar_container

@docstring.dedent_interpd
def barh(self, *args, **kwargs):
def barh(self, y, width, height=0.8, left=None, *, align="center",
**kwargs):
r"""
Make a horizontal bar plot.

Call signatures::

bar(y, width, *, align='center', **kwargs)
bar(y, width, height, *, align='center', **kwargs)
bar(y, width, height, left, *, align='center', **kwargs)

The bars are positioned at *y* with the given *align*. Their
The bars are positioned at *y* with the given *align*\ment. Their
dimensions are given by *width* and *height*. The horizontal baseline
is *left* (default 0).

Each of *y*, *width*, *height*, and *left* may either be a scalar
applying to all bars, or it may be a sequence of length N providing a
separate value for each bar.


Parameters
----------
y : scalar or array-like
Expand Down Expand Up @@ -2235,35 +2191,9 @@ def barh(self, *args, **kwargs):
%(Rectangle)s

"""
# this is using the lambdas to do the arg/kwarg unpacking rather
# than trying to re-implement all of that logic our selves.
matchers = [
(lambda y, width, height=0.8, left=None, **kwargs:
(False, y, width, height, left, kwargs)),
(lambda bottom, width, height=0.8, left=None, **kwargs:
(True, bottom, width, height, left, kwargs)),
]
excs = []
for matcher in matchers:
try:
dp, y, width, height, left, kwargs = matcher(*args, **kwargs)
except TypeError as e:
# This can only come from a no-match as there is
# no other logic in the matchers.
excs.append(e)
else:
break
else:
raise excs[0]

if dp:
warnings.warn(
"The *bottom* kwarg to `barh` is deprecated use *y* instead. "
"Support for *bottom* will be removed in Matplotlib 3.0",
mplDeprecation, stacklevel=2)
kwargs.setdefault('orientation', 'horizontal')
patches = self.bar(x=left, height=height, width=width,
bottom=y, **kwargs)
patches = self.bar(x=left, height=height, width=width, bottom=y,
align=align, **kwargs)
return patches

@_preprocess_data(label_namer=None)
Expand Down
38 changes: 3 additions & 35 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,14 +1441,14 @@ def test_marker_edges():
def test_bar_tick_label_single():
# From 2516: plot bar with array of string labels for x axis
ax = plt.gca()
ax.bar(0, 1, tick_label='0')
ax.bar(0, 1, align='edge', tick_label='0')

# Reuse testcase from above for a labeled data test
data = {"a": 0, "b": 1}
fig = plt.figure()
ax = fig.add_subplot(111)
ax = plt.gca()
ax.bar("a", "b", tick_label='0', data=data)
ax.bar("a", "b", align='edge', tick_label='0', data=data)


def test_bar_ticklabel_fail():
Expand Down Expand Up @@ -5343,7 +5343,7 @@ def test_ls_ds_conflict():

def test_bar_uint8():
xs = [0, 1, 2, 3]
b = plt.bar(np.array(xs, dtype=np.uint8), [2, 3, 4, 5])
b = plt.bar(np.array(xs, dtype=np.uint8), [2, 3, 4, 5], align="edge")
for (patch, x) in zip(b.patches, xs):
assert patch.xy[0] == x

Expand Down Expand Up @@ -5639,38 +5639,6 @@ def test_twinx_knows_limits():
assert_array_equal(xtwin.viewLim.intervalx, ax2.viewLim.intervalx)


@pytest.mark.style('mpl20')
@pytest.mark.parametrize('args, kwargs, warning_count',
[((1, 1), {'width': 1, 'bottom': 1}, 0),
((1, ), {'height': 1, 'bottom': 1}, 0),
((), {'x': 1, 'height': 1}, 0),
((), {'left': 1, 'height': 1}, 1)])
def test_bar_signature(args, kwargs, warning_count):
fig, ax = plt.subplots()
with warnings.catch_warnings(record=True) as w:
r, = ax.bar(*args, **kwargs)

assert r.get_width() == kwargs.get('width', 0.8)
assert r.get_y() == kwargs.get('bottom', 0)
assert len(w) == warning_count


@pytest.mark.style('mpl20')
@pytest.mark.parametrize('args, kwargs, warning_count',
[((1, 1), {'height': 1, 'left': 1}, 0),
((1, ), {'width': 1, 'left': 1}, 0),
((), {'y': 1, 'width': 1}, 0),
((), {'bottom': 1, 'width': 1}, 1)])
def test_barh_signature(args, kwargs, warning_count):
fig, ax = plt.subplots()
with warnings.catch_warnings(record=True) as w:
r, = ax.barh(*args, **kwargs)

assert r.get_height() == kwargs.get('height', 0.8)
assert r.get_x() == kwargs.get('left', 0)
assert len(w) == warning_count


def test_zero_linewidth():
# Check that setting a zero linewidth doesn't error
plt.plot([0, 1], [0, 1], ls='--', lw=0)
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 @@ -29,7 +29,7 @@ def test_bbox_inches_tight():
# the bottom values for stacked bar chart
fig, ax = plt.subplots(1, 1)
for row in range(rows):
ax.bar(ind, data[row], width, bottom=yoff, color='b')
ax.bar(ind, data[row], width, bottom=yoff, align='edge', color='b')
yoff = yoff + data[row]
cellText.append([''])
plt.xticks([])
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def test_legend_auto2():
fig = plt.figure()
ax = fig.add_subplot(111)
x = np.arange(100)
b1 = ax.bar(x, x, color='m')
b2 = ax.bar(x, x[::-1], color='g')
b1 = ax.bar(x, x, align='edge', color='m')
b2 = ax.bar(x, x[::-1], align='edge', color='g')
ax.legend([b1[0], b2[0]], ['up', 'down'], loc=0)


Expand Down
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_bar3d():
ys = np.arange(20)
cs = [c] * len(xs)
cs[0] = 'c'
ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8)
ax.bar(xs, ys, zs=z, zdir='y', align='edge', color=cs, alpha=0.8)


@image_comparison(
Expand Down