Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 44ce103

Browse files
committed
Sort and uniquify style entries in figure options.
Fixes the first two points of #5341.
1 parent f443b12 commit 44ce103

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

lib/matplotlib/backends/qt_editor/figureoptions.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,38 @@ 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+
# 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
92+
8493
curvelabels = sorted(linedict.keys())
8594
for label in curvelabels:
8695
line = linedict[label]
8796
color = rgb2hex(colorConverter.to_rgb(line.get_color()))
8897
ec = rgb2hex(colorConverter.to_rgb(line.get_markeredgecolor()))
8998
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-
]
99+
curvedata = [
100+
('Label', label),
101+
sep,
102+
(None, '<b>Line</b>'),
103+
('Line Style', prepare_data(LINESTYLES, line.get_linestyle())),
104+
('Draw Style', prepare_data(DRAWSTYLES, line.get_drawstyle())),
105+
('Width', line.get_linewidth()),
106+
('Color', color),
107+
sep,
108+
(None, '<b>Marker</b>'),
109+
('Style', prepare_data(MARKERS, line.get_marker())),
110+
('Size', line.get_markersize()),
111+
('Facecolor', fc),
112+
('Edgecolor', ec)]
104113
curves.append([curvedata, label, ""])
105114

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

0 commit comments

Comments
 (0)