|
1 | 1 | """
|
2 |
| -Module for creating Sankey diagrams using matplotlib |
| 2 | +Module for creating Sankey diagrams using Matplotlib. |
3 | 3 | """
|
4 | 4 |
|
5 | 5 | import logging
|
|
29 | 29 |
|
30 | 30 | class Sankey(object):
|
31 | 31 | """
|
32 |
| - Sankey diagram in matplotlib |
| 32 | + Sankey diagram. |
33 | 33 |
|
34 | 34 | Sankey diagrams are a specific type of flow diagram, in which
|
35 | 35 | the width of the arrows is shown proportionally to the flow
|
@@ -354,81 +354,84 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='',
|
354 | 354 | """
|
355 | 355 | Add a simple Sankey diagram with flows at the same hierarchical level.
|
356 | 356 |
|
357 |
| - Return value is the instance of :class:`Sankey`. |
358 |
| -
|
359 |
| - Optional keyword arguments: |
360 |
| -
|
361 |
| - =============== =================================================== |
362 |
| - Keyword Description |
363 |
| - =============== =================================================== |
364 |
| - *patchlabel* label to be placed at the center of the diagram |
365 |
| - Note: *label* (not *patchlabel*) will be passed to |
366 |
| - the patch through ``**kwargs`` and can be used to |
367 |
| - create an entry in the legend. |
368 |
| - *flows* array of flow values |
369 |
| - By convention, inputs are positive and outputs are |
370 |
| - negative. |
371 |
| - *orientations* list of orientations of the paths |
372 |
| - Valid values are 1 (from/to the top), 0 (from/to |
373 |
| - the left or right), or -1 (from/to the bottom). If |
374 |
| - *orientations* == 0, inputs will break in from the |
375 |
| - left and outputs will break away to the right. |
376 |
| - *labels* list of specifications of the labels for the flows |
377 |
| - Each value may be *None* (no labels), '' (just |
378 |
| - label the quantities), or a labeling string. If a |
379 |
| - single value is provided, it will be applied to all |
380 |
| - flows. If an entry is a non-empty string, then the |
381 |
| - quantity for the corresponding flow will be shown |
382 |
| - below the string. However, if the *unit* of the |
383 |
| - main diagram is None, then quantities are never |
384 |
| - shown, regardless of the value of this argument. |
385 |
| - *trunklength* length between the bases of the input and output |
386 |
| - groups |
387 |
| - *pathlengths* list of lengths of the arrows before break-in or |
388 |
| - after break-away |
389 |
| - If a single value is given, then it will be applied |
390 |
| - to the first (inside) paths on the top and bottom, |
391 |
| - and the length of all other arrows will be |
392 |
| - justified accordingly. The *pathlengths* are not |
393 |
| - applied to the horizontal inputs and outputs. |
394 |
| - *prior* index of the prior diagram to which this diagram |
395 |
| - should be connected |
396 |
| - *connect* a (prior, this) tuple indexing the flow of the |
397 |
| - prior diagram and the flow of this diagram which |
398 |
| - should be connected |
399 |
| - If this is the first diagram or *prior* is *None*, |
400 |
| - *connect* will be ignored. |
401 |
| - *rotation* angle of rotation of the diagram [deg] |
402 |
| - *rotation* is ignored if this diagram is connected |
403 |
| - to an existing one (using *prior* and *connect*). |
404 |
| - The interpretation of the *orientations* argument |
405 |
| - will be rotated accordingly (e.g., if *rotation* |
406 |
| - == 90, an *orientations* entry of 1 means to/from |
407 |
| - the left). |
408 |
| - =============== =================================================== |
409 |
| -
|
410 |
| - Valid kwargs are :meth:`matplotlib.patches.PathPatch` arguments: |
| 357 | + Parameters |
| 358 | + ---------- |
| 359 | + patchlabel : str |
| 360 | + Label to be placed at the center of the diagram. |
| 361 | + Note that *label* (not *patchlabel*) can be passed as keyword |
| 362 | + argument to create an entry in the legend. |
| 363 | +
|
| 364 | + flows : list of float |
| 365 | + Array of flow values. By convention, inputs are positive and |
| 366 | + outputs are negative. |
| 367 | +
|
| 368 | + Flows are placed along the top of the diagram from the inside out |
| 369 | + in order of their index within *flows*. They are placed along the |
| 370 | + sides of the diagram from the top down and along the bottom from |
| 371 | + the outside in. |
| 372 | +
|
| 373 | + If the sum of the inputs and outputs is |
| 374 | + nonzero, the discrepancy will appear as a cubic Bezier curve along |
| 375 | + the top and bottom edges of the trunk. |
| 376 | +
|
| 377 | + orientations : list of {-1, 0, 1} |
| 378 | + List of orientations of the flows (or a single orientation to be |
| 379 | + used for all flows). Valid values are 0 (inputs from |
| 380 | + the left, outputs to the right), 1 (from and to the top) or -1 |
| 381 | + (from and to the bottom). |
| 382 | +
|
| 383 | + labels : list of (str or None) |
| 384 | + List of labels for the flows (or a single label to be used for all |
| 385 | + flows). Each label may be *None* (no label), or a labeling string. |
| 386 | + If an entry is a (possibly empty) string, then the quantity for the |
| 387 | + corresponding flow will be shown below the string. However, if |
| 388 | + the *unit* of the main diagram is None, then quantities are never |
| 389 | + shown, regardless of the value of this argument. |
| 390 | +
|
| 391 | + trunklength : float |
| 392 | + Length between the bases of the input and output groups (in |
| 393 | + data-space units). |
| 394 | +
|
| 395 | + pathlengths : list of float |
| 396 | + List of lengths of the vertical arrows before break-in or after |
| 397 | + break-away. If a single value is given, then it will be applied to |
| 398 | + the first (inside) paths on the top and bottom, and the length of |
| 399 | + all other arrows will be justified accordingly. The *pathlengths* |
| 400 | + are not applied to the horizontal inputs and outputs. |
| 401 | +
|
| 402 | + prior : int |
| 403 | + Index of the prior diagram to which this diagram should be |
| 404 | + connected. |
| 405 | +
|
| 406 | + connect : (int, int) |
| 407 | + A (prior, this) tuple indexing the flow of the prior diagram and |
| 408 | + the flow of this diagram which should be connected. If this is the |
| 409 | + first diagram or *prior* is *None*, *connect* will be ignored. |
| 410 | +
|
| 411 | + rotation : float |
| 412 | + Angle of rotation of the diagram in degrees. The interpretation of |
| 413 | + the *orientations* argument will be rotated accordingly (e.g., if |
| 414 | + *rotation* == 90, an *orientations* entry of 1 means to/from the |
| 415 | + left). *rotation* is ignored if this diagram is connected to an |
| 416 | + existing one (using *prior* and *connect*). |
| 417 | +
|
| 418 | + Returns |
| 419 | + ------- |
| 420 | + Sankey |
| 421 | + The current `.Sankey` instance. |
| 422 | +
|
| 423 | + Other Parameters |
| 424 | + ---------------- |
| 425 | + **kwargs |
| 426 | + Additional keyword arguments set `matplotlib.patches.PathPatch` |
| 427 | + properties, listed below. For example, one may want to use |
| 428 | + ``fill=False`` or ``label="A legend entry"``. |
411 | 429 |
|
412 | 430 | %(Patch)s
|
413 | 431 |
|
414 |
| - As examples, ``fill=False`` and ``label='A legend entry'``. |
415 |
| - By default, ``facecolor='#bfd1d4'`` (light blue) and |
416 |
| - ``linewidth=0.5``. |
417 |
| -
|
418 |
| - The indexing parameters (*prior* and *connect*) are zero-based. |
419 |
| -
|
420 |
| - The flows are placed along the top of the diagram from the inside out |
421 |
| - in order of their index within the *flows* list or array. They are |
422 |
| - placed along the sides of the diagram from the top down and along the |
423 |
| - bottom from the outside in. |
424 |
| -
|
425 |
| - If the sum of the inputs and outputs is nonzero, the discrepancy |
426 |
| - will appear as a cubic Bezier curve along the top and bottom edges of |
427 |
| - the trunk. |
428 |
| -
|
429 |
| - .. seealso:: |
430 |
| -
|
431 |
| - :meth:`finish` |
| 432 | + See Also |
| 433 | + -------- |
| 434 | + Sankey.finish |
432 | 435 | """
|
433 | 436 | # Check and preprocess the arguments.
|
434 | 437 | if flows is None:
|
|
0 commit comments