Skip to content

Make code match comment in sankey. #11974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/api/next_api_changes/2018-08-29-AL-sankey.rst
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 3 additions & 6 deletions lib/matplotlib/sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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))
Expand Down