8000 Improvements to Sankey class by kdavies4 · Pull Request #1574 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Improvements to Sankey class #1574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 7, 2012
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
In Sankey, prevented appended lists of labels
  • Loading branch information
kdavies4 committed Dec 7, 2012
commit f813278c26d72407e13488ef3a7d7dc02d2f9e7e
22 changes: 9 additions & 13 deletions lib/matplotlib/sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,22 +755,18 @@ 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could get rid of the enumeration here, right? Also, just to make sure, there is a subtle difference in result. Previously, this for-loop would update the labels list, while the new code would not. This may not be of consequence, but it is a difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch--I removed the enumeration (commit de1f1f4). The second for loop can be merged without any problems. I think that the separation was from a previous hack.

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
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
Expand Down
0