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 c52ef28

Browse filesBrowse files
committed
Merge pull request #5342 from anntzer/sort-and-uniquify-styles-in-figure-options
ENH: Sort and uniquify style entries in figure options.
2 parents 380a894 + 2bbffe1 commit c52ef28
Copy full SHA for c52ef28

File tree

Expand file treeCollapse file tree

1 file changed

+39
-17
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+39
-17
lines changed

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

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/qt_editor/figureoptions.py
+39-17Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,51 @@ def figure_edit(axes, parent=None):
7878
continue
7979
linedict[label] = line
8080
curves = []
81-
linestyles = list(six.iteritems(LINESTYLES))
82-
drawstyles = list(six.iteritems(DRAWSTYLES))
83-
markers = list(six.iteritems(MARKERS))
81+
82+
def prepare_data(d, init):
83+
"""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), ...]`.
93+
"""
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]))
105+
84106
curvelabels = sorted(linedict.keys())
85107
for label in curvelabels:
86108
line = linedict[label]
87109
color = rgb2hex(colorConverter.to_rgb(line.get_color()))
88110
ec = rgb2hex(colorConverter.to_rgb(line.get_markeredgecolor()))
89111
fc = rgb2hex(colorConverter.to_rgb(line.get_markerfacecolor()))
90-
curvedata = [('Label', label),
91-
sep,
92-
(None, '<b>Line</b>'),
93-
('Line Style', [line.get_linestyle()] + linestyles),
94-
('Draw Style', [line.get_drawstyle()] + drawstyles),
95-
('Width', line.get_linewidth()),
96-
('Color', color),
97-
sep,
98-
(None, '<b>Marker</b>'),
99-
('Style', [line.get_marker()] + markers),
100-
('Size', line.get_markersize()),
101-
('Facecolor', fc),
102-
('Edgecolor', ec),
103-
]
112+
curvedata = [
113+
('Label', label),
114+
sep,
115+
(None, '<b>Line</b>'),
116+
('Line Style', prepare_data(LINESTYLES, line.get_linestyle())),
117+
('Draw Style', prepare_data(DRAWSTYLES, line.get_drawstyle())),
118+
('Width', line.get_linewidth()),
119+
('Color', color),
120+
sep,
121+
(None, '<b>Marker</b>'),
122+
('Style', prepare_data(MARKERS, line.get_marker())),
123+
('Size', line.get_markersize()),
124+
('Facecolor', fc),
125+
('Edgecolor', ec)]
104126
curves.append([curvedata, label, ""])
105127

106128
# make sure that there is at least one displayed curve

0 commit comments

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