diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index ae08af92fcdf..f2ddb3852df3 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4757,6 +4757,7 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False, for filling between two sets of x-values """ + if not rcParams['_internal.classic_mode']: color_aliases = mcoll._color_aliases kwargs = cbook.normalize_kwargs(kwargs, color_aliases) @@ -4774,6 +4775,11 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False, y1 = ma.masked_invalid(self.convert_yunits(y1)) y2 = ma.masked_invalid(self.convert_yunits(y2)) + for name, array in [('x', x), ('y1', y1), ('y2', y2)]: + if array.ndim > 1: + raise ValueError('Input passed into argument "%r"' % name + + 'is not 1-dimensional.') + if y1.ndim == 0: y1 = np.ones_like(x) * y1 if y2.ndim == 0: @@ -4918,6 +4924,7 @@ def fill_betweenx(self, y, x1, x2=0, where=None, for filling between two sets of y-values """ + if not rcParams['_internal.classic_mode']: color_aliases = mcoll._color_aliases kwargs = cbook.normalize_kwargs(kwargs, color_aliases) @@ -4934,6 +4941,11 @@ def fill_betweenx(self, y, x1, x2=0, where=None, x1 = ma.masked_invalid(self.convert_xunits(x1)) x2 = ma.masked_invalid(self.convert_xunits(x2)) + for name, array in [('y', y), ('x1', x1), ('x2', x2)]: + if array.ndim > 1: + raise ValueError('Input passed into argument "%r"' % name + + 'is not 1-dimensional.') + if x1.ndim == 0: x1 = np.ones_like(y) * x1 if x2.ndim == 0: diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index dde3c5a806ef..6f506c59913d 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -725,6 +725,45 @@ def test_polycollection_joinstyle(): ax.set_ybound(0, 3) +@cleanup +def test_fill_between_2d_x_input(): + x = np.zeros((2, 2)) + y1 = 3 + y2 = 3 + + fig = plt.figure() + ax = fig.add_subplot(211) + with pytest.raises(ValueError): + ax.plot(x, y1, x, y2, color='black') + ax.fill_between(x, y1, y2) + + +@cleanup +def test_fill_between_2d_y1_input(): + x = np.arange(0.0, 2, 0.02) + y1 = np.zeros((2, 2)) + y2 = 3 + + fig = plt.figure() + ax = fig.add_subplot(211) + with pytest.raises(ValueError): + ax.plot(x, y1, x, y2, color='black') + ax.fill_between(x, y1, y2) + + +@cleanup +def test_fill_between_2d_y2_input(): + x = np.arange(0.0, 2, 0.02) + y1 = 3 + y2 = np.zeros((2, 2)) + + fig = plt.figure() + ax = fig.add_subplot(211) + with pytest.raises(ValueError): + ax.plot(x, y1, x, y2, color='black') + ax.fill_between(x, y1, y2) + + @image_comparison(baseline_images=['fill_between_interpolate'], remove_text=True) def test_fill_between_interpolate(): @@ -4801,6 +4840,45 @@ def test_tick_param_label_rotation(): assert text.get_rotation() == 90 +@cleanup +def test_fill_betweenx_2d_y_input(): + y = np.zeros((2, 2)) + x1 = 3 + x2 = 3 + + fig = plt.figure() + ax = fig.add_subplot(211) + with pytest.raises(ValueError): + ax.plot(y, x1, y, x2, color='black') + ax.fill_betweenx(y, x1, x2) + + +@cleanup +def test_fill_betweenx_2d_x1_input(): + y = np.arange(0.0, 2, 0.02) + x1 = np.zeros((2, 2)) + x2 = 3 + + fig = plt.figure() + ax = fig.add_subplot(211) + with pytest.raises(ValueError): + ax.plot(y, x1, y, x2, color='black') + ax.fill_betweenx(y, x1, x2) + + +@cleanup +def test_fill_betweenx_2d_x2_input(): + y = np.arange(0.0, 2, 0.02) + x1 = 3 + x2 = np.zeros((2, 2)) + + fig = plt.figure() + ax = fig.add_subplot(211) + with pytest.raises(ValueError): + ax.plot(y, x1, y, x2, color='black') + ax.fill_betweenx(y, x1, x2) + + @cleanup(style='default') def test_fillbetween_cycle(): fig, ax = plt.subplots()