Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3ec18e3

Browse filesBrowse files
authored
Merge pull request #11096 from anntzer/barsig
Remove support for bar(left=...) (as opposed to bar(x=...)).
2 parents 17447c2 + 6f43017 commit 3ec18e3
Copy full SHA for 3ec18e3

File tree

Expand file treeCollapse file tree

6 files changed

+25
-122
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+25
-122
lines changed
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``bar``/``barh`` no longer accepts ``left``/``bottom`` as first named argument
2+
``````````````````````````````````````````````````````````````````````````````
3+
4+
These arguments were renamed in 2.0 to ``x``/``y`` following the change of the
5+
default alignment from ``edge`` to ``center``.

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+13-83Lines changed: 13 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,25 +1814,19 @@ def step(self, x, y, *args, **kwargs):
18141814
replace_all_args=True
18151815
)
18161816
@docstring.dedent_interpd
1817-
def bar(self, *args, **kwargs):
1817+
def bar(self, x, height, width=0.8, bottom=None, *, align="center",
1818+
**kwargs):
18181819
r"""
18191820
Make a bar plot.
18201821
1821-
Call signatures::
1822-
1823-
bar(x, height, *, align='center', **kwargs)
1824-
bar(x, height, width, *, align='center', **kwargs)
1825-
bar(x, height, width, bottom, *, align='center', **kwargs)
1826-
1827-
The bars are positioned at *x* with the given *align* ment. Their
1822+
The bars are positioned at *x* with the given *align*\ment. Their
18281823
dimensions are given by *width* and *height*. The vertical baseline
18291824
is *bottom* (default 0).
18301825
18311826
Each of *x*, *height*, *width*, and *bottom* may either be a scalar
18321827
applying to all bars, or it may be a sequence of length N providing a
18331828
separate value for each bar.
18341829
1835-
18361830
Parameters
18371831
----------
18381832
x : sequence of scalars
@@ -1927,55 +1921,22 @@ def bar(self, *args, **kwargs):
19271921
19281922
"""
19291923
kwargs = cbook.normalize_kwargs(kwargs, mpatches.Patch._alias_map)
1930-
# this is using the lambdas to do the arg/kwarg unpacking rather
1931-
# than trying to re-implement all of that logic our selves.
1932-
matchers = [
1933-
(lambda x, height, width=0.8, bottom=None, **kwargs:
1934-
(False, x, height, width, bottom, kwargs)),
1935-
(lambda left, height, width=0.8, bottom=None, **kwargs:
1936-
(True, left, height, width, bottom, kwargs)),
1937-
]
1938-
exps = []
1939-
for matcher in matchers:
1940-
try:
1941-
dp, x, height, width, y, kwargs = matcher(*args, **kwargs)
1942-
except TypeError as e:
1943-
# This can only come from a no-match as there is
1944-
# no other logic in the matchers.
1945-
exps.append(e)
1946-
else:
1947-
break
1948-
else:
1949-
raise exps[0]
1950-
# if we matched the second-case, then the user passed in
1951-
# left=val as a kwarg which we want to deprecate
1952-
if dp:
1953-
warnings.warn(
1954-
"The *left* kwarg to `bar` is deprecated use *x* instead. "
1955-
"Support for *left* will be removed in Matplotlib 3.0",
1956-
mplDeprecation, stacklevel=2)
19571924
color = kwargs.pop('color', None)
19581925
if color is None:
19591926
color = self._get_patches_for_fill.get_next_color()
19601927
edgecolor = kwargs.pop('edgecolor', None)
19611928
linewidth = kwargs.pop('linewidth', None)
19621929

1963-
# Because xerr and yerr will be passed to errorbar,
1964-
# most dimension checking and processing will be left
1965-
# to the errorbar method.
1930+
# Because xerr and yerr will be passed to errorbar, most dimension
1931+
# checking and processing will be left to the errorbar method.
19661932
xerr = kwargs.pop('xerr', None)
19671933
yerr = kwargs.pop('yerr', None)
1968-
error_kw = kwargs.pop('error_kw', dict())
1934+
error_kw = kwargs.pop('error_kw', {})
19691935
ecolor = kwargs.pop('ecolor', 'k')
19701936
capsize = kwargs.pop('capsize', rcParams["errorbar.capsize"])
19711937
error_kw.setdefault('ecolor', ecolor)
19721938
error_kw.setdefault('capsize', capsize)
19731939

1974-
if rcParams['_internal.classic_mode']:
1975-
align = kwargs.pop('align', 'edge')
1976-
else:
1977-
align = kwargs.pop('align', 'center')
1978-
19791940
orientation = kwargs.pop('orientation', 'vertical')
19801941
log = kwargs.pop('log', False)
19811942
label = kwargs.pop('label', '')
@@ -1984,8 +1945,9 @@ def bar(self, *args, **kwargs):
19841945
adjust_ylim = False
19851946
adjust_xlim = False
19861947

1948+
y = bottom # Matches barh call signature.
19871949
if orientation == 'vertical':
1988-
if y is None:
1950+
if bottom is None:
19891951
if self.get_yscale() == 'log':
19901952
adjust_ylim = True
19911953
y = 0
@@ -2126,25 +2088,19 @@ def bar(self, *args, **kwargs):
21262088
return bar_container
21272089

21282090
@docstring.dedent_interpd
2129-
def barh(self, *args, **kwargs):
2091+
def barh(self, y, width, height=0.8, left=None, *, align="center",
2092+
**kwargs):
21302093
r"""
21312094
Make a horizontal bar plot.
21322095
2133-
Call signatures::
2134-
2135-
bar(y, width, *, align='center', **kwargs)
2136-
bar(y, width, height, *, align='center', **kwargs)
2137-
bar(y, width, height, left, *, align='center', **kwargs)
2138-
2139-
The bars are positioned at *y* with the given *align*. Their
2096+
The bars are positioned at *y* with the given *align*\ment. Their
21402097
dimensions are given by *width* and *height*. The horizontal baseline
21412098
is *left* (default 0).
21422099
21432100
Each of *y*, *width*, *height*, and *left* may either be a scalar
21442101
applying to all bars, or it may be a sequence of length N providing a
21452102
separate value for each bar.
21462103
2147-
21482104
Parameters
21492105
----------
21502106
y : scalar or array-like
@@ -2235,35 +2191,9 @@ def barh(self, *args, **kwargs):
22352191
%(Rectangle)s
22362192
22372193
"""
2238-
# this is using the lambdas to do the arg/kwarg unpacking rather
2239-
# than trying to re-implement all of that logic our selves.
2240-
matchers = [
2241-
(lambda y, width, height=0.8, left=None, **kwargs:
2242-
(False, y, width, height, left, kwargs)),
2243-
(lambda bottom, width, height=0.8, left=None, **kwargs:
2244-
(True, bottom, width, height, left, kwargs)),
2245-
]
2246-
excs = []
2247-
for matcher in matchers:
2248-
try:
2249-
dp, y, width, height, left, kwargs = matcher(*args, **kwargs)
2250-
except TypeError as e:
2251-
# This can only come from a no-match as there is
2252-
# no other logic in the matchers.
2253-
excs.append(e)
2254-
else:
2255-
break
2256-
else:
2257-
raise excs[0]
2258-
2259-
if dp:
2260-
warnings.warn(
2261-
"The *bottom* kwarg to `barh` is deprecated use *y* instead. "
2262-
"Support for *bottom* will be removed in Matplotlib 3.0",
2263-
mplDeprecation, stacklevel=2)
22642194
kwargs.setdefault('orientation', 'horizontal')
2265-
patches = self.bar(x=left, height=height, width=width,
2266-
bottom=y, **kwargs)
2195+
patches = self.bar(x=left, height=height, width=width, bottom=y,
2196+
align=align, **kwargs)
22672197
return patches
22682198

22692199
@_preprocess_data(label_namer=None)

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+3-35Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,14 +1441,14 @@ def test_marker_edges():
14411441
def test_bar_tick_label_single():
14421442
# From 2516: plot bar with array of string labels for x axis
14431443
ax = plt.gca()
1444-
ax.bar(0, 1, tick_label='0')
1444+
ax.bar(0, 1, align='edge', tick_label='0')
14451445

14461446
# Reuse testcase from above for a labeled data test
14471447
data = {"a": 0, "b": 1}
14481448
fig = plt.figure()
14491449
ax = fig.add_subplot(111)
14501450
ax = plt.gca()
1451-
ax.bar("a", "b", tick_label='0', data=data)
1451+
ax.bar("a", "b", align='edge', tick_label='0', data=data)
14521452

14531453

14541454
def test_bar_ticklabel_fail():
@@ -5343,7 +5343,7 @@ def test_ls_ds_conflict():
53435343

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

@@ -5639,38 +5639,6 @@ def test_twinx_knows_limits():
56395639
assert_array_equal(xtwin.viewLim.intervalx, ax2.viewLim.intervalx)
56405640

56415641

5642-
@pytest.mark.style('mpl20')
5643-
@pytest.mark.parametrize('args, kwargs, warning_count',
5644-
[((1, 1), {'width': 1, 'bottom': 1}, 0),
5645-
((1, ), {'height': 1, 'bottom': 1}, 0),
5646-
((), {'x': 1, 'height': 1}, 0),
5647-
((), {'left': 1, 'height': 1}, 1)])
5648-
def test_bar_signature(args, kwargs, warning_count):
5649-
fig, ax = plt.subplots()
5650-
with warnings.catch_warnings(record=True) as w:
5651-
r, = ax.bar(*args, **kwargs)
5652-
5653-
assert r.get_width() == kwargs.get('width', 0.8)
5654-
assert r.get_y() == kwargs.get('bottom', 0)
5655-
assert len(w) == warning_count
5656-
5657-
5658-
@pytest.mark.style('mpl20')
5659-
@pytest.mark.parametrize('args, kwargs, warning_count',
5660-
[((1, 1), {'height': 1, 'left': 1}, 0),
5661-
((1, ), {'width': 1, 'left': 1}, 0),
5662-
((), {'y': 1, 'width': 1}, 0),
5663-
((), {'bottom': 1, 'width': 1}, 1)])
5664-
def test_barh_signature(args, kwargs, warning_count):
5665-
fig, ax = plt.subplots()
5666-
with warnings.catch_warnings(record=True) as w:
5667-
r, = ax.barh(*args, **kwargs)
5668-
5669-
assert r.get_height() == kwargs.get('height', 0.8)
5670-
assert r.get_x() == kwargs.get('left', 0)
5671-
assert len(w) == warning_count
5672-
5673-
56745642
def test_zero_linewidth():
56755643
# Check that setting a zero linewidth doesn't error
56765644
plt.plot([0, 1], [0, 1], ls='--', lw=0)

‎lib/matplotlib/tests/test_bbox_tight.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_bbox_tight.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_bbox_inches_tight():
2929
# the bottom values for stacked bar chart
3030
fig, ax = plt.subplots(1, 1)
3131
for row in range(rows):
32-
ax.bar(ind, data[row], width, bottom=yoff, color='b')
32+
ax.bar(ind, data[row], width, bottom=yoff, align='edge', color='b')
3333
yoff = yoff + data[row]
3434
cellText.append([''])
3535
plt.xticks([])

‎lib/matplotlib/tests/test_legend.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_legend.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def test_legend_auto2():
4848
fig = plt.figure()
4949
ax = fig.add_subplot(111)
5050
x = np.arange(100)
51-
b1 = ax.bar(x, x, color='m')
52-
b2 = ax.bar(x, x[::-1], color='g')
51+
b1 = ax.bar(x, x, align='edge', color='m')
52+
b2 = ax.bar(x, x[::-1], align='edge', color='g')
5353
ax.legend([b1[0], b2[0]], ['up', 'down'], loc=0)
5454

5555

‎lib/mpl_toolkits/tests/test_mplot3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_mplot3d.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_bar3d():
1818
ys = np.arange(20)
1919
cs = [c] * len(xs)
2020
cs[0] = 'c'
21-
ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8)
21+
ax.bar(xs, ys, zs=z, zdir='y', align='edge', color=cs, alpha=0.8)
2222

2323

2424
@image_comparison(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.