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

Skip to content

Commit ff4bb1e

Browse files
committed
Merge pull request #563 from mdboom/issue563
sankey.add() has mutable defaults
2 parents fcf4301 + d37b027 commit ff4bb1e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/matplotlib/sankey.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ def _revert(self, path, first_action=Path.LINETO):
245245
#return path
246246

247247
@docstring.dedent_interpd
248-
def add(self, patchlabel='', flows=np.array([1.0, -1.0]),
249-
orientations=[0, 0], labels='', trunklength=1.0, pathlengths=0.25,
250-
prior=None, connect=(0, 0), rotation=0, **kwargs):
248+
def add(self, patchlabel='', flows=None, orientations=None, labels='',
249+
trunklength=1.0, pathlengths=0.25, prior=None, connect=(0, 0),
250+
rotation=0, **kwargs):
251251
"""
252252
Add a simple Sankey diagram with flows at the same hierarchical level.
253253
@@ -328,13 +328,18 @@ def add(self, patchlabel='', flows=np.array([1.0, -1.0]),
328328
:meth:`finish`
329329
"""
330330
# Check and preprocess the arguments.
331-
flows = np.array(flows)
331+
if flows is None:
332+
flows = np.array([1.0, -1.0])
333+
else:
334+
flows = np.array(flows)
332335
n = flows.shape[0] # Number of flows
333336
if rotation == None:
334337
rotation = 0
335338
else:
336339
# In the code below, angles are expressed in deg/90
337340
rotation /= 90.0
341+
if orientations is None:
342+
orientations = [0, 0]
338343
assert len(orientations) == n, (
339344
"orientations and flows must have the same length.\n"
340345
"orientations has length %d, but flows has length %d."

0 commit comments

Comments
 (0)