@@ -104,12 +104,14 @@ def _arc(self, quadrant=0, cw=True, radius=1, center=(0,0)):
104104 # Negate x.
105105 if cw :
106106 # Swap x and y.
107- vertices = np .column_stack ((- ARC_VERTICES [:,1 ], ARC_VERTICES [:,0 ]))
107+ vertices = np .column_stack ((- ARC_VERTICES [:,1 ],
108+ ARC_VERTICES [:,0 ]))
108109 else :
109- vertices = np .column_stack ((- ARC_VERTICES [:,0 ], ARC_VERTICES [:,1 ]))
110+ vertices = np .column_stack ((- ARC_VERTICES [:,0 ],
111+ ARC_VERTICES [:,1 ]))
110112 if quadrant > 1 : radius = - radius # Rotate 180 deg.
111- return zip (ARC_CODES ,
112- radius * vertices + np .tile (center , (ARC_VERTICES .shape [0 ], 1 )))
113+ return zip (ARC_CODES , radius * vertices +
114+ np .tile (center , (ARC_VERTICES .shape [0 ], 1 )))
113115
114116 def _add_input (self , path , angle , flow , length ):
115117 """Add an input to a path and return its tip and label locations.
@@ -196,9 +198,11 @@ def _add_output(self, path, angle, flow, length):
196198 else :
197199 path .append ((Path .LINETO , [x , y ]))
198200 path .extend ([(Path .LINETO , [x , y + sign * length ]),
199- (Path .LINETO , [x - self .shoulder , y + sign * length ]),
201+ (Path .LINETO , [x - self .shoulder ,
202+ y + sign * length ]),
200203 (Path .LINETO , tip ),
201- (Path .LINETO , [x + self .shoulder - flow , y + sign * length ]),
204+ (Path .LINETO , [x + self .shoulder - flow ,
205+ y + sign * length ]),
202206 (Path .LINETO , [x - flow , y + sign * length ])])
203207 path .extend (self ._arc (quadrant = quadrant ,
204208 cw = angle == DOWN ,
@@ -317,13 +321,13 @@ def add(self, patchlabel='', flows=np.array([1.0,-1.0]), orientations=[0,0],
317321 if rotation == None :
318322 rotation = 0
319323 else :
320- rotation /= 90.0 # In the code below, angles are expressed in deg/90.
324+ rotation /= 90.0 # In the code below, angles are expressed in deg/90
321325 assert len (orientations ) == n , ("orientations and flows must have the "
322326 "same length.\n orientations has length "
323327 "%d, but flows has length %d."
324328 % len (orientations ), n )
325329 if getattr (labels , '__iter__' , False ):
326- # iterable() isn't used because it would give True if labels is a string.
330+ # iterable() isn't used because it would give True if labels is a string
327331 assert len (labels ) == n , ("If labels is a list, then labels and "
328332 "flows must have the same length.\n "
329333 "labels has length %d, but flows has "
@@ -422,7 +426,8 @@ def add(self, patchlabel='', flows=np.array([1.0,-1.0]), orientations=[0,0],
422426 lllength = pathlengths
423427 d = dict (RIGHT = pathlengths )
424428 pathlengths = [d .get (angle , 0 ) for angle in angles ]
425- # Determine the lengths of the top-side arrows from the middle outwards.
429+ # Determine the lengths of the top-side arrows
430+ # from the middle outwards.
426431 for i , (angle , is_input , flow ) \
427432 in enumerate (zip (angles , are_inputs , scaled_flows )):
428433 if angle == DOWN and is_input :
@@ -431,7 +436,8 @@ def add(self, patchlabel='', flows=np.array([1.0,-1.0]), orientations=[0,0],
431436 elif angle == UP and not is_input :
432437 pathlengths [i ] = urlength
433438 urlength -= flow # Flow is negative for outputs.
434- # Determine the lengths of the bottom-side arrows from the middle outwards.
439+ # Determine the lengths of the bottom-side arrows
440+ # from the middle outwards.
435441 for i , (angle , is_input , flow ) \
436442 in enumerate (zip (angles , are_inputs , scaled_flows )[::- 1 ]):
437443 if angle == UP and is_input :
@@ -440,7 +446,8 @@ def add(self, patchlabel='', flows=np.array([1.0,-1.0]), orientations=[0,0],
440446 elif angle == DOWN and not is_input :
441447 pathlengths [n - i - 1 ] = lrlength
442448 lrlength -= flow
443- # Determine the lengths of the left-side arrows from the bottom upwards.
449+ # Determine the lengths of the left-side arrows
450+ # from the bottom upwards.
444451 has_left_input = False
445452 for i , (angle , is_input , spec ) \
446453 in enumerate (zip (angles , are_inputs , zip (scaled_flows ,
@@ -451,7 +458,8 @@ def add(self, patchlabel='', flows=np.array([1.0,-1.0]), orientations=[0,0],
451458 pathlengths [n - i - 1 ] = 0
452459 else :
453460 has_left_input = True
454- # Determine the lengths of the right-side arrows from the top downwards.
461+ # Determine the lengths of the right-side arrows
462+ # from the top downwards.
455463 has_right_output = False
456464 for i , (angle , is_input , spec ) \
457465 in enumerate (zip (angles , are_inputs , zip (scaled_flows ,
@@ -499,40 +507,57 @@ def add(self, patchlabel='', flows=np.array([1.0,-1.0]), orientations=[0,0],
499507 label_locations = np .zeros ((n ,2 ))
500508 # Add the top-side inputs and outputs from the middle outwards.
501509 for i , (angle , is_input , spec ) \
502- in enumerate (zip (angles , are_inputs , zip (scaled_flows , pathlengths ))):
510+ in enumerate (zip (angles , are_inputs ,
511+ zip (scaled_flows , pathlengths ))):
503512 if angle == DOWN and is_input :
504- tips [i ,:], label_locations [i ,:] = self ._add_input (ulpath , angle , * spec )
513+ tips [i ,:], label_locations [i ,:] = self ._add_input (ulpath , angle ,
514+ * spec )
505515 elif angle == UP and not is_input :
506- tips [i ,:], label_locations [i ,:] = self ._add_output (urpath , angle , * spec )
516+ tips [i ,:], label_locations [i ,:] = self ._add_output (urpath ,
517+ angle , * spec )
507518 # Add the bottom-side inputs and outputs from the middle outwards.
508519 for i , (angle , is_input , spec ) \
509- in enumerate (zip (angles , are_inputs , zip (scaled_flows , pathlengths ))[::- 1 ]):
520+ in enumerate (zip (angles , are_inputs ,
521+ zip (scaled_flows , pathlengths ))[::- 1 ]):
510522 if angle == UP and is_input :
511- tips [n - i - 1 ,:], label_locations [n - i - 1 ,:] = self ._add_input (llpath , angle , * spec )
523+ (tips [n - i - 1 ,:],
524+ label_locations [n - i - 1 ,:]) = self ._add_input (llpath , angle ,
525+ * spec )
512526 elif angle == DOWN and not is_input :
513- tips [n - i - 1 ,:], label_locations [n - i - 1 ,:] = self ._add_output (lrpath , angle , * spec )
527+ (tips [n - i - 1 ,:],
528+ label_locations [n - i - 1 ,:]) = self ._add_output (lrpath , angle ,
529+ * spec )
514530 # Add the left-side inputs from the bottom upwards.
515531 has_left_input = False
516532 for i , (angle , is_input , spec ) \
517- in enumerate (zip (angles , are_inputs , zip (scaled_flows , pathlengths ))[::- 1 ]):
533+ in enumerate (zip (angles , are_inputs ,
534+ zip (scaled_flows , pathlengths ))[::- 1 ]):
518535 if angle == RIGHT and is_input :
519536 if not has_left_input :
520- # Make sure the lower path extends at least as far as the upper one.
537+ # Make sure the lower path extends
538+ # at least as far as the upper one.
521539 if llpath [- 1 ][1 ][0 ] > ulpath [- 1 ][1 ][0 ]:
522- llpath .append ((Path .LINETO , [ulpath [- 1 ][1 ][0 ], llpath [- 1 ][1 ][1 ]]))
540+ llpath .append ((Path .LINETO , [ulpath [- 1 ][1 ][0 ],
541+ llpath [- 1 ][1 ][1 ]]))
523542 has_left_input = True
524- tips [n - i - 1 ,:], label_locations [n - i - 1 ,:] = self ._add_input (llpath , angle , * spec )
543+ (tips [n - i - 1 ,:],
544+ label_locations [n - i - 1 ,:]) = self ._add_input (llpath , angle ,
545+ * spec )
525546 # Add the right-side outputs from the top downwards.
526547 has_right_output = False
527548 for i , (angle , is_input , spec ) \
528- in enumerate (zip (angles , are_inputs , zip (scaled_flows , pathlengths ))):
549+ in enumerate (zip (angles , are_inputs ,
550+ zip (scaled_flows , pathlengths ))):
529551 if angle == RIGHT and not is_input :
530552 if not has_right_output :
531- # Make sure the upper path extends at least as far as the lower one.
553+ # Make sure the upper path extends
554+ # at least as far as the lower one.
532555 if urpath [- 1 ][1 ][0 ] < lrpath [- 1 ][1 ][0 ]:
533- urpath .append ((Path .LINETO , [lrpath [- 1 ][1 ][0 ], urpath [- 1 ][1 ][1 ]]))
556+ urpath .append ((Path .LINETO , [lrpath [- 1 ][1 ][0 ],
557+ urpath [- 1 ][1 ][1 ]]))
534558 has_right_output = True
535- tips [i ,:], label_locations [i ,:] = self ._add_output (urpath , angle , * spec )
559+ (tips [i ,:],
560+ label_locations [i ,:]) = self ._add_output (urpath , angle , * spec )
536561 # Trim any hanging vertices.
537562 if not has_left_input :
538563 ulpath .pop ()
@@ -542,8 +567,8 @@ def add(self, patchlabel='', flows=np.array([1.0,-1.0]), orientations=[0,0],
542567 urpath .pop ()
543568
544569 # Concatenate the subpaths in the correct order (clockwise from top).
545- path = (urpath + self ._revert (lrpath ) + llpath + self ._revert (ulpath )
546- + [(Path .CLOSEPOLY , urpath [0 ][1 ])])
570+ path = (urpath + self ._revert (lrpath ) + llpath + self ._revert (ulpath ) +
571+ [(Path .CLOSEPOLY , urpath [0 ][1 ])])
547572
548573 # Create a patch with the Sankey outline.
549574 codes , vertices = zip (* path )
@@ -561,7 +586,8 @@ def _get_angle(a, r):
561586 vertices = rotate (vertices )
562587 text = self .ax .text (0 , 0 , s = patchlabel , ha = 'center' , va = 'center' )
563588 else :
564- rotation = self .diagrams [prior ].angles [connect [0 ]] - angles [connect [1 ]]
589+ rotation = (self .diagrams [prior ].angles [connect [0 ]] -
590+ angles [connect [1 ]])
565591 angles = [_get_angle (angle , rotation ) for angle in angles ]
566592 rotate = Affine2D ().rotate_deg (rotation * 90 ).transform_point
567593 tips = rotate (tips )
@@ -580,8 +606,8 @@ def _get_angle(a, r):
580606 xs , ys = zip (* vertices )
581607 self .ax .plot (xs , ys , 'go-' )
582608 patch = PathPatch (Path (vertices , codes ),
583- fc = kwargs .pop ('fc' , kwargs .pop ('facecolor' , # Custom defaults
584- '#bfd1d4' )),
609+ fc = kwargs .pop ('fc' , kwargs .pop ('facecolor' ,
610+ '#bfd1d4' )), # Custom defaults
585611 lw = kwargs .pop ('lw' , kwargs .pop ('linewidth' ,
586612 '0.5' )),
587613 ** kwargs )
@@ -592,7 +618,7 @@ def _get_angle(a, r):
592618 if labels [i ] is None or angle is None :
593619 labels [i ] = ''
594620 elif self .unit is not None :
595- quantity = self .format % abs (number ) + self .unit
621+ quantity = self .format % abs (number ) + self .unit
596622 if labels [i ] != '' :
597623 labels [i ] += "\n "
598624 labels [i ] += quantity
@@ -608,10 +634,14 @@ def _get_angle(a, r):
608634 # user wants to provide labels later.
609635
610636 # Expand the size of the diagram if necessary.
611- self .extent = (min (np .min (vertices [:,0 ]), np .min (label_locations [:,0 ]), self .extent [0 ]),
612- max (np .max (vertices [:,0 ]), np .max (label_locations [:,0 ]), self .extent [1 ]),
613- min (np .min (vertices [:,1 ]), np .min (label_locations [:,1 ]), self .extent [2 ]),
614- max (np .max (vertices [:,1 ]), np .max (label_locations [:,1 ]), self .extent [3 ]))
637+ self .extent = (min (np .min (vertices [:,0 ]), np .min (label_locations [:,0 ]),
638+ self .extent [0 ]),
639+ max (np .max (vertices [:,0 ]), np .max (label_locations [:,0 ]),
640+ self .extent [1 ]),
641+ min (np .min (vertices [:,1 ]), np .min (label_locations [:,1 ]),
642+ self .extent [2 ]),
643+ max (np .max (vertices [:,1 ]), np .max (label_locations [:,1 ]),
644+ self .extent [3 ]))
615645 # Include both vertices _and_ label locations in the extents; there are
616646 # where either could determine the margins (e.g., arrow shoulders).
617647
@@ -750,7 +780,7 @@ def __init__(self, ax=None, scale=1.0, unit='', format='%G', gap=0.25,
750780
751781 **Examples:**
752782
753- .. plot:: mpl_examples/api/sankey_demo .py
783+ .. plot:: mpl_examples/api/sankey_demo_basics .py
754784 """
755785 # Check the arguments.
756786 assert gap >= 0 , ("The gap is negative.\n This isn't allowed because it "
0 commit comments