-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Sort and uniquify style entries in figure options. #5342
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,29 +78,38 @@ def figure_edit(axes, parent=None): | |
continue | ||
linedict[label] = line | ||
curves = [] | ||
linestyles = list(six.iteritems(LINESTYLES)) | ||
drawstyles = list(six.iteritems(DRAWSTYLES)) | ||
markers = list(six.iteritems(MARKERS)) | ||
|
||
def prepare_data(d, init): | ||
"""Prepare entry for FormLayout. | ||
""" | ||
# List items in dict, dropping duplicate values, sorting by values. | ||
kvs = [(k, v) for v, k in | ||
sorted({v: k for k, v in d.items()}.items())] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure that this will not be deterministic as the iteration order of dictionaries is random process to process in 3.4+. Dict comprehensions are the same as a series of This might be better done as dd = defaultdict(list)
for k, v in d.items():
dd[v].append(k)
Uniqed = {k: v[0] for k, v in dd.items()} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be non-deterministic only in the sense that the "nothing" entry (the only one with multiple internal synonyms) may be internally represented as one of "nothing", "none", "None" or None depending on which one comes up last in the iteration. From the UI point of view there is no difference. See edited docstring to come. |
||
# Find the unique kept key with the same value as the init value. | ||
canonical_init, = ({k for k, v in d.items() if v == d[init]}. | ||
intersection(k for k, v in kvs)) | ||
return [canonical_init] + kvs | ||
|
||
curvelabels = sorted(linedict.keys()) | ||
for label in curvelabels: | ||
line = linedict[label] | ||
color = rgb2hex(colorConverter.to_rgb(line.get_color())) | ||
ec = rgb2hex(colorConverter.to_rgb(line.get_markeredgecolor())) | ||
fc = rgb2hex(colorConverter.to_rgb(line.get_markerfacecolor())) | ||
curvedata = [('Label', label), | ||
sep, | ||
(None, '<b>Line</b>'), | ||
('Line Style', [line.get_linestyle()] + linestyles), | ||
('Draw Style', [line.get_drawstyle()] + drawstyles), | ||
('Width', line.get_linewidth()), | ||
('Color', color), | ||
sep, | ||
(None, '<b>Marker</b>'), | ||
('Style', [line.get_marker()] + markers), | ||
('Size', line.get_markersize()), | ||
('Facecolor', fc), | ||
('Edgecolor', ec), | ||
] | ||
curvedata = [ | ||
('Label', label), | ||
sep, | ||
(None, '<b>Line</b>'), | ||
('Line Style', prepare_data(LINESTYLES, line.get_linestyle())), | ||
('Draw Style', prepare_data(DRAWSTYLES, line.get_drawstyle())), | ||
('Width', line.get_linewidth()), | ||
('Color', color), | ||
sep, | ||
(None, '<b>Marker</b>'), | ||
('Style', prepare_data(MARKERS, line.get_marker())), | ||
('Size', line.get_markersize()), | ||
('Facecolor', fc), | ||
('Edgecolor', ec)] | ||
curves.append([curvedata, label, ""]) | ||
|
||
# make sure that there is at least one displayed curve | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please document the expected input parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.