Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2bbffe1

Browse filesBrowse files
committed
Clarify the implementation of prepare_data.
1 parent 4cab2e7 commit 2bbffe1
Copy full SHA for 2bbffe1

File tree

Expand file treeCollapse file tree

1 file changed

+20
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+20
-7
lines changed

‎lib/matplotlib/backends/qt_editor/figureoptions.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/qt_editor/figureoptions.py
+20-7Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,27 @@ def figure_edit(axes, parent=None):
8181

8282
def prepare_data(d, init):
8383
"""Prepare entry for FormLayout.
84+
85+
`d` is a mapping of shorthands to style names (a single style may
86+
have multiple shorthands, in particular the shorthands `None`,
87+
`"None"`, `"none"` and `""` are synonyms); `init` is one shorthand
88+
of the initial style.
89+
90+
This function returns an list suitable for initializing a
91+
FormLayout combobox, namely `[initial_name, (shorthand,
92+
style_name), (shorthand, style_name), ...]`.
8493
"""
85-
# List items in dict, dropping duplicate values, sorting by values.
86-
kvs = [(k, v) for v, k in
87-
sorted({v: k for k, v in d.items()}.items())]
88-
# Find the unique kept key with the same value as the init value.
89-
canonical_init, = ({k for k, v in d.items() if v == d[init]}.
90-
intersection(k for k, v in kvs))
91-
return [canonical_init] + kvs
94+
# Drop duplicate shorthands from dict (by overwriting them during
95+
# the dict comprehension).
96+
name2short = {name: short for short, name in d.items()}
97+
# Convert back to {shorthand: name}.
98+
short2name = {short: name for name, short in name2short.items()}
99+
# Find the kept shorthand for the style specified by init.
100+
canonical_init = name2short[d[init]]
101+
# Sort by representation and prepend the initial value.
102+
return ([canonical_init] +
103+
sorted(short2name.items(),
104+
key=lambda short_and_name: short_and_name[1]))
92105

93106
curvelabels = sorted(linedict.keys())
94107
for label in curvelabels:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.