Skip to content

Commit c2fb60f

Browse files
committed
Fix checking of 'labels' argument to Sankey.add.
Test by manually running the sankey examples.
1 parent 4432fda commit c2fb60f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/matplotlib/sankey.py

Lines changed: 7 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 cbook, docstring
13+
from matplotlib import docstring
1414
from matplotlib import rcParams
1515

1616
_log = logging.getLogger(__name__)
@@ -453,12 +453,13 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='',
453453
f"The shapes of 'flows' {np.shape(flows)} and 'orientations' "
454454
f"{np.shape(orientations)} are incompatible"
455455
) from None
456-
if not cbook.is_scalar_or_string(labels) and len(labels) != n:
456+
try:
457+
labels = np.broadcast_to(labels, n)
458+
except ValueError:
457459
raise ValueError(
458-
f"The lengths of 'flows' ({n}) and 'labels' ({len(labels)}) "
459-
f"are incompatible")
460-
else:
461-
labels = [labels] * n
460+
f"The shapes of 'flows' {np.shape(flows)} and 'labels' "
461+
f"{np.shape(labels)} are incompatible"
462+
) from None
462463
if trunklength < 0:
463464
raise ValueError(
464465
"'trunklength' is negative, which is not allowed because it "

0 commit comments

Comments
 (0)