diff --git a/doc/api/api_changes/2017-11-24-AL.rst b/doc/api/api_changes/2017-11-24-AL.rst new file mode 100644 index 000000000000..74cf300d5d79 --- /dev/null +++ b/doc/api/api_changes/2017-11-24-AL.rst @@ -0,0 +1,7 @@ +Deprecations +```````````` + +When given 2D inputs with non-matching numbers of columns, `~.pyplot.plot` +currently cycles through the columns of the narrower input, until all the +columns of the wider input have been plotted. This behavior is deprecated; in +the future, only broadcasting (1 column to *n* columns) will be performed. diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 357e26907b1a..dce69ff8e27e 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -391,6 +391,9 @@ def _plot_args(self, tup, kwargs): func = self._makefill ncx, ncy = x.shape[1], y.shape[1] + if ncx > 1 and ncy > 1 and ncx != ncy: + cbook.warn_deprecated("2.2", "cycling among columns of inputs " + "with non-matching shapes is deprecated.") for j in xrange(max(ncx, ncy)): seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs) ret.append(seg) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index e8c4de74bc48..6db9be0b0aeb 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -26,7 +26,8 @@ import matplotlib.patches as mpatches import matplotlib.colors as mcolors from numpy.testing import assert_allclose, assert_array_equal -from matplotlib.cbook import IgnoredKeywordWarning +from matplotlib.cbook import ( + IgnoredKeywordWarning, MatplotlibDeprecationWarning) from matplotlib.cbook._backports import broadcast_to # Note: Some test cases are run twice: once normally and once with labeled data @@ -5498,3 +5499,8 @@ def test_empty_errorbar_legend(): ax.errorbar([], [], xerr=[], label='empty y') ax.errorbar([], [], yerr=[], label='empty x') ax.legend() + + +def test_plot_columns_cycle_deprecation(): + with pytest.warns(MatplotlibDeprecationWarning): + plt.plot(np.zeros((2, 2)), np.zeros((2, 3)))