8000 Fix python3 issues in some examples by jenshnielsen · Pull Request #3831 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix python3 issues in some examples #3831

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 13 commits into from
Jan 1, 2015
Prev Previous commit
Next Next commit
Use iteritems to iterate over markers
  • Loading branch information
jenshnielsen committed Dec 30, 2014
commit 273462d54b5b864b70a4331bca024bf01c802b87
5 changes: 4 additions & 1 deletion examples/lines_bars_and_markers/marker_reference.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Reference for filled- and unfilled-marker types included with Matplotlib.
"""
from six import iteritems
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
Expand Down Expand Up @@ -32,7 +33,9 @@ def split_list(a_list):
fig, axes = plt.subplots(ncols=2)

# Filter out filled markers and marker settings that do nothing.
unfilled_markers = [m for m, func in Line2D.markers.items()
# We use iteritems from six to make sure that we get an iterator
# in both python 2 and 3
unfilled_markers = [m for m, func in iteritems(Line2D.markers)
if func != 'nothing' and m not in Line2D.filled_markers]
# Reverse-sort for pretty
Copy link
Member

Choose a reason for hiding this comment

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

put the comment above the relevant statement

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

unfilled_markers = sorted(unfilled_markers, key=str)[::-1]
Copy link
Member Author

Choose a reason for hiding this comment

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

This does not actually reproduce the original python2 behaviour (ints are sorted before strings). Rather this converts the int to a string before sorting so 2 will be the same as '2'

There don't seem to be an easy way to restore python2 sorting order without rolling out our own function which seems overkill in this case.

Expand Down
0