diff --git a/doc/api/next_api_changes/2018-04-20-AL.rst b/doc/api/next_api_changes/2018-04-20-AL.rst new file mode 100644 index 000000000000..f38a95df11b1 --- /dev/null +++ b/doc/api/next_api_changes/2018-04-20-AL.rst @@ -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``. diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index e502d3b8ec6a..28245fd087e5 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -1814,17 +1814,12 @@ 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). @@ -1832,7 +1827,6 @@ def bar(self, *args, **kwargs): 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 @@ -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', '') @@ -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 @@ -2126,17 +2088,12 @@ 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). @@ -2144,7 +2101,6 @@ def barh(self, *args, **kwargs): 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 @@ -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) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index aff0fede59a7..89fc5dc0882c 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -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(): @@ -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 @@ -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) diff --git a/lib/matplotlib/tests/test_bbox_tight.py b/lib/matplotlib/tests/test_bbox_tight.py index 5eb4b6b3ba2c..4f5942e90df2 100644 --- a/lib/matplotlib/tests/test_bbox_tight.py +++ b/lib/matplotlib/tests/test_bbox_tight.py @@ -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([]) diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index 9aaf5dc27970..b1d176ec8a0f 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -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) diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index 0a506db92adf..18a6a896fd83 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -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(