8000 Merge pull request #11974 from anntzer/sankey · matplotlib/matplotlib@ec6a45a · GitHub
[go: up one dir, main page]

Skip to content

Commit ec6a45a

Browse files
authored
Merge pull request #11974 from anntzer/sankey
Make code match comment in sankey.
2 parents d4c1e72 + 7b0414e commit ec6a45a

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Passing a single string as *labels* to `Sankey.add`
2+
```````````````````````````````````````````````````
3+
4+
Previously, `Sankey.add` would only accept a single string as the *labels*
5+
argument if its length is equal to the number of flows, in which case it would
6+
use one character of the string for each flow.
7+
8+
The behavior has been changed to match the documented one: when a single string
9+
is passed, it is used to label all the flows.

lib/matplotlib/sankey.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from matplotlib.path import Path
1111
from matplotlib.patches import PathPatch
1212
from matplotlib.transforms import Affine2D
13-
from matplotlib import docstring
13+
from matplotlib import cbook, docstring
1414
from matplotlib import rcParams
1515

1616
_log = logging.getLogger(__name__)
@@ -449,11 +449,8 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='',
449449
"orientations and flows must have the same length.\n"
450450
"orientations has length %d, but flows has length %d."
451451
% (len(orientations), n))
452-
if labels != '' and getattr(labels, '__iter__', False):
453-
# np.iterable() isn't used because it would give True if labels is
454-
# a string
455-
if len(labels) != n:
456-
raise ValueError(
452+
if not cbook.is_scalar_or_string(labels) and len(labels) != n:
453+
raise ValueError(
457454
"If labels is a list, then labels and flows must have the "
458455
"same length.\nlabels has length %d, but flows has length %d."
459456
% (len(labels), n))

0 commit comments

Comments
 (0)
0