Skip to content

Sankey5 #1407

Closed
wants to merge 7 commits into from
View
2 examples/api/sankey_demo_rankine.py
@@ -5,7 +5,7 @@
from matplotlib.sankey import Sankey
-fig = plt.figure(figsize=(8, 12))
+fig = plt.figure(figsize=(8, 9))
ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[],
title="Rankine Power Cycle: Example 8.6 from Moran and Shapiro\n"
+ "\x22Fundamentals of Engineering Thermodynamics\x22, 6th ed., 2008")
View
67 lib/matplotlib/sankey.py
@@ -11,8 +11,8 @@
# http://matplotlib.org/examples/api/sankey_demo_old.html
# Modifications by Kevin Davies (kld@alumni.carnegiemellon.edu) 6/3/2011:
# --Used arcs for the curves (so that the widths of the paths are uniform)
-# --Converted the function to a class and created methods to join
-# multiple simple Sankey diagrams
+# --Converted the function to a class and created methods to join multiple
+# simple Sankey diagrams
# --Provided handling for cases where the total of the inputs isn't 100
# Now, the default layout is based on the assumption that the inputs sum to
# 1. A scaling parameter can be used in other cases.
@@ -28,7 +28,7 @@
# inputs/outputs are now specified via an orientation of 0, and there may
# be several of each.
# --Added assertions to catch common calling errors
-# -Added the physical unit as a string argument to be used in the labels, so
+# --Added the physical unit as a string argument to be used in the labels, so
# that the values of the flows can usually be applied automatically
# --Added an argument for a minimum magnitude below which flows are not shown
# --Added a tapered trunk in the case that the flows do not sum to 0
@@ -271,13 +271,13 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='',
*orientations* == 0, inputs will break in from the
left and outputs will break away to the right.
*labels* list of specifications of the labels for the flows
- Each value may be None (no labels), '' (just label
- the quantities), or a labeling string. If a single
- value is provided, it will be applied to all flows.
- If an entry is a non-empty string, then the
+ Each value may be *None* (no labels), '' (just
+ label the quantities), or a labeling string. If a
+ single value is provided, it will be applied to all
+ flows. If an entry is a non-empty string, then the
quantity for the corresponding flow will be shown
below the string. However, if the *unit* of the
- main diagram is None, then quantities are never
+ main diagram is *None*, then quantities are never
shown, regardless of the value of this argument.
*trunklength* length between the bases of the input and output
groups
@@ -293,7 +293,7 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='',
*connect* a (prior, this) tuple indexing the flow of the
prior diagram and the flow of this diagram which
should be connected
- If this is the first diagram or *prior* is None,
+ If this is the first diagram or *prior* is *None*,
*connect* will be ignored.
*rotation* angle of rotation of the diagram [deg]
*rotation* is ignored if this diagram is connected
@@ -336,7 +336,7 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='',
if rotation == None:
rotation = 0
else:
- # In the code below, angles are expressed in deg/90
+ # In the code below, angles are expressed in deg/90.
rotation /= 90.0
if orientations is None:
orientations = [0, 0]
@@ -613,11 +613,11 @@ def _get_angle(a, r):
vertices = translate(rotate(vertices))
kwds = dict(s=patchlabel, ha='center', va='center')
text = self.ax.text(*offset, **kwds)
- if False: # Debug
- print "llpath\n", llpath
- print "ulpath\n", self._revert(ulpath)
- print "urpath\n", urpath
- print "lrpath\n", self._revert(lrpath)
+ if False: # Debug
+ print("llpath\n", llpath)
+ print("ulpath\n", self._revert(ulpath))
+ print("urpath\n", urpath)
+ print("lrpath\n", self._revert(lrpath))
xs, ys = zip(*vertices)
self.ax.plot(xs, ys, 'go-')
patch = PathPatch(Path(vertices, codes),
@@ -628,22 +628,21 @@ def _get_angle(a, r):
self.ax.add_patch(patch)
# Add the path labels.
- for i, (number, angle) in enumerate(zip(flows, angles)):
- if labels[i] is None or angle is None:
- labels[i] = ''
+ texts = []
+ for i, (number, angle, label, location) in enumerate(zip(flows, angles,
+ labels, label_locations)):
+ if label is None or angle is None:
+ label = ''
elif self.unit is not None:
quantity = self.format % abs(number) + self.unit
- if labels[i] != '':
- labels[i] += "\n"
- labels[i] += quantity
- texts = []
- for i, (label, location) in enumerate(zip(labels, label_locations)):
- if label:
- s = label
- else:
- s = ''
+ if label != '':
+ label += "\n"
+ label += quantity
+ if label != '':
+ label += "\n"
+ label += quantity
texts.append(self.ax.text(x=location[0], y=location[1],
- s=s,
+ s=label,
ha='center', va='center'))
# Text objects are placed even they are empty (as long as the magnitude
# of the corresponding flow is larger than the tolerance) in case the
@@ -693,7 +692,7 @@ def finish(self):
(DOWN), and an output from the top side will have
an angle of 1 (UP). If a flow has been skipped
(because its magnitude is less than *tolerance*),
- then its angle will be None.
+ then its angle will be *None*.
*tips* array in which each row is an [x, y] pair
indicating the positions of the tips (or "dips") of
the flow paths
@@ -718,7 +717,7 @@ def finish(self):
self.ax.set_aspect('equal', adjustable='datalim')
return self.diagrams
- def __init__(self, ax=None, scale=1.0, unit='', format='%G', gap=0.25,
+ def __init__(self, ax=None, scale=1.0, unit='', format='%G ', gap=0.25,
radius=0.1, shoulder=0.03, offset=0.15, head_angle=100,
margin=0.4, tolerance=1e-6, **kwargs):
"""
@@ -730,7 +729,7 @@ def __init__(self, ax=None, scale=1.0, unit='', format='%G', gap=0.25,
Field Description
=============== ===================================================
*ax* axes onto which the data should be plotted
- If *ax* isn't provided, new axes will be created.
+ If *ax* is not provided, new axes will be created.
*scale* scaling factor for the flows
*scale* sizes the width of the paths in order to
maintain proper layout. The same scale is applied
@@ -741,15 +740,15 @@ def __init__(self, ax=None, scale=1.0, unit='', format='%G', gap=0.25,
approximately -1.0).
*unit* string representing the physical unit associated
with the flow quantities
- If *unit* is None, then none of the quantities are
- labeled.
+ If *unit* is *None*, then none of the quantities
+ are labeled.
*format* a Python number formatting string to be used in
labeling the flow as a quantity (i.e., a number
times a unit, where the unit is given)
*gap* space between paths that break in/break away
to/from the top or bottom
*radius* inner radius of the vertical paths
- *shoulder* size of the shoulders of output arrowS
+ *shoulder* size of the shoulders of output arrows
*offset* text offset (from the dip or tip of the arrow)
*head_angle* angle of the arrow heads (and negative of the angle
of the tails) [deg]
Something went wrong with that request. Please try again.