Skip to content

Commit 487e517

Browse files
committed
Sort and uniquify style entries in figure options.
Fixes the first two points of #5341.
1 parent 544b27b commit 487e517

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

lib/matplotlib/backends/qt_editor/figureoptions.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,36 @@ 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+
def prepare_data(d, init):
82+
"""Prepare entry for FormLayout.
83+
"""
84+
# List items in dict, dropping duplicate values, sorting by values.
85+
kvs = [(k, v) for v, k in
86+
sorted({v: k for k, v in d.items()}.items())]
87+
# Find the unique kept key with the same value as the init value.
88+
canonical_init, = ({k for k, v in d.items() if v == d[init]}.
89+
intersection(k for k, v in kvs))
90+
return [canonical_init] + kvs
8491
curvelabels = sorted(linedict.keys())
8592
for label in curvelabels:
8693
line = linedict[label]
8794
color = rgb2hex(colorConverter.to_rgb(line.get_color()))
8895
ec = rgb2hex(colorConverter.to_rgb(line.get_markeredgecolor()))
8996
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-
]
97+
curvedata = [
98+
('Label', label),
99+
sep,
100+
(None, '<b>Line</b>'),
101+
('Line Style', prepare_data(LINESTYLES, line.get_linestyle())),
102+
('Draw Style', prepare_data(DRAWSTYLES, line.get_drawstyle())),
103+
('Width', line.get_linewidth()),
104+
('Color', color),
105+
sep,
106+
(None, '<b>Marker</b>'),
107+
('Style', prepare_data(MARKERS, line.get_marker())),
108+
('Size', line.get_markersize()),
109+
('Facecolor', fc),
110+
('Edgecolor', ec)]
104111
curves.append([curvedata, label, ""])
105112

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

0 commit comments

Comments
 (0)