From 4b9f77d56e076c36a2f56ef158bfc209037771c2 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 20 Aug 2012 11:02:26 -0400 Subject: [PATCH 1/2] Remove the mutable kward from sankey.add. Fixes #563. --- lib/matplotlib/sankey.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/sankey.py b/lib/matplotlib/sankey.py index 1c24bd55d3ce..41c95e84708a 100755 --- a/lib/matplotlib/sankey.py +++ b/lib/matplotlib/sankey.py @@ -245,9 +245,9 @@ def _revert(self, path, first_action=Path.LINETO): #return path @docstring.dedent_interpd - def add(self, patchlabel='', flows=np.array([1.0, -1.0]), - orientations=[0, 0], labels='', trunklength=1.0, pathlengths=0.25, - prior=None, connect=(0, 0), rotation=0, **kwargs): + def add(self, patchlabel='', flows=None, orientations=[0, 0], labels='', + trunklength=1.0, pathlengths=0.25, prior=None, connect=(0, 0), + rotation=0, **kwargs): """ Add a simple Sankey diagram with flows at the same hierarchical level. @@ -328,7 +328,10 @@ def add(self, patchlabel='', flows=np.array([1.0, -1.0]), :meth:`finish` """ # Check and preprocess the arguments. - flows = np.array(flows) + if flows is None: + flows = np.array([1.0, -1.0]) + else: + flows = np.array(flows) n = flows.shape[0] # Number of flows if rotation == None: rotation = 0 From d37b0273aabd56bbe891c47e3551f507f4244565 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 21 Aug 2012 09:15:27 -0400 Subject: [PATCH 2/2] Fix the orientations kwarg in sankey.add --- lib/matplotlib/sankey.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/sankey.py b/lib/matplotlib/sankey.py index 41c95e84708a..cccd9b79e442 100755 --- a/lib/matplotlib/sankey.py +++ b/lib/matplotlib/sankey.py @@ -245,7 +245,7 @@ def _revert(self, path, first_action=Path.LINETO): #return path @docstring.dedent_interpd - def add(self, patchlabel='', flows=None, orientations=[0, 0], labels='', + def add(self, patchlabel='', flows=None, orientations=None, labels='', trunklength=1.0, pathlengths=0.25, prior=None, connect=(0, 0), rotation=0, **kwargs): """ @@ -338,6 +338,8 @@ def add(self, patchlabel='', flows=None, orientations=[0, 0], labels='', else: # In the code below, angles are expressed in deg/90 rotation /= 90.0 + if orientations is None: + orientations = [0, 0] assert len(orientations) == n, ( "orientations and flows must have the same length.\n" "orientations has length %d, but flows has length %d."