diff --git a/doc/api/next_api_changes/2018-08-29-AL-sankey.rst b/doc/api/next_api_changes/2018-08-29-AL-sankey.rst new file mode 100644 index 000000000000..9386d5bde3ed --- /dev/null +++ b/doc/api/next_api_changes/2018-08-29-AL-sankey.rst @@ -0,0 +1,9 @@ +Passing a single string as *labels* to `Sankey.add` +``````````````````````````````````````````````````` + +Previously, `Sankey.add` would only accept a single string as the *labels* +argument if its length is equal to the number of flows, in which case it would +use one character of the string for each flow. + +The behavior has been changed to match the documented one: when a single string +is passed, it is used to label all the flows. diff --git a/lib/matplotlib/sankey.py b/lib/matplotlib/sankey.py index 77964a76882e..aa75a1d0bafa 100644 --- a/lib/matplotlib/sankey.py +++ b/lib/matplotlib/sankey.py @@ -10,7 +10,7 @@ from matplotlib.path import Path from matplotlib.patches import PathPatch from matplotlib.transforms import Affine2D -from matplotlib import docstring +from matplotlib import cbook, docstring from matplotlib import rcParams _log = logging.getLogger(__name__) @@ -449,11 +449,8 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='', "orientations and flows must have the same length.\n" "orientations has length %d, but flows has length %d." % (len(orientations), n)) - if labels != '' and getattr(labels, '__iter__', False): - # np.iterable() isn't used because it would give True if labels is - # a string - if len(labels) != n: - raise ValueError( + if not cbook.is_scalar_or_string(labels) and len(labels) != n: + raise ValueError( "If labels is a list, then labels and flows must have the " "same length.\nlabels has length %d, but flows has length %d." % (len(labels), n))