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

Skip to content

Commit c608ae1

Browse files
authored
Merge pull request #9826 from anntzer/matching-column-plots
API: Deprecate column cycling when plot() inputs have nonmatching shapes.
2 parents 8d86fa5 + d9545b3 commit c608ae1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

doc/api/api_changes/2017-11-24-AL.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Deprecations
2+
````````````
3+
4+
When given 2D inputs with non-matching numbers of columns, `~.pyplot.plot`
5+
currently cycles through the columns of the narrower input, until all the
6+
columns of the wider input have been plotted. This behavior is deprecated; in
7+
the future, only broadcasting (1 column to *n* columns) will be performed.

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ def _plot_args(self, tup, kwargs):
391391
func = self._makefill
392392

393393
ncx, ncy = x.shape[1], y.shape[1]
394+
if ncx > 1 and ncy > 1 and ncx != ncy:
395+
cbook.warn_deprecated("2.2", "cycling among columns of inputs "
396+
"with non-matching shapes is deprecated.")
394397
for j in xrange(max(ncx, ncy)):
395398
seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
396399
ret.append(seg)

lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import matplotlib.patches as mpatches
2727
import matplotlib.colors as mcolors
2828
from numpy.testing import assert_allclose, assert_array_equal
29-
from matplotlib.cbook import IgnoredKeywordWarning
29+
from matplotlib.cbook import (
30+
IgnoredKeywordWarning, MatplotlibDeprecationWarning)
3031
from matplotlib.cbook._backports import broadcast_to
3132

3233
# Note: Some test cases are run twice: once normally and once with labeled data
@@ -5498,3 +5499,8 @@ def test_empty_errorbar_legend():
54985499
ax.errorbar([], [], xerr=[], label='empty y')
54995500
ax.errorbar([], [], yerr=[], label='empty x')
55005501
ax.legend()
5502+
5503+
5504+
def test_plot_columns_cycle_deprecation():
5505+
with pytest.warns(MatplotlibDeprecationWarning):
5506+
plt.plot(np.zeros((2, 2)), np.zeros((2, 3)))

0 commit comments

Comments
 (0)