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

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

Merged
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
43 changes: 26 additions & 17 deletions 43 lib/matplotlib/backends/qt_editor/figureoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

"""
# 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())]
Copy link
Member

Choose a reason for hiding this comment

The 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 d[k]=v so the same override semantics apply.

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()}

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.