18
18
from matplotlib .backends .qt4_compat import QtGui
19
19
from matplotlib import markers
20
20
21
+
21
22
def get_icon (name ):
22
23
import matplotlib
23
24
basedir = osp .join (matplotlib .rcParams ['datapath' ], 'images' )
24
25
return QtGui .QIcon (osp .join (basedir , name ))
25
26
26
- LINESTYLES = {
27
- '-' : 'Solid' ,
27
+ LINESTYLES = {'-' : 'Solid' ,
28
28
'--' : 'Dashed' ,
29
29
'-.' : 'DashDot' ,
30
30
':' : 'Dotted' ,
@@ -34,9 +34,10 @@ def get_icon(name):
34
34
35
35
MARKERS = markers .MarkerStyle .markers
36
36
37
+
37
38
def figure_edit (axes , parent = None ):
38
39
"""Edit matplotlib figure options"""
39
- sep = (None , None ) # separator
40
+ sep = (None , None ) # separator
40
41
41
42
has_curve = len (axes .get_lines ()) > 0
42
43
@@ -53,7 +54,9 @@ def figure_edit(axes, parent=None):
53
54
(None , "<b>Y-Axis</b>" ),
54
55
('Min' , ymin ), ('Max' , ymax ),
55
56
('Label' , axes .get_ylabel ()),
56
- ('Scale' , [axes .get_yscale (), 'linear' , 'log' ])
57
+ ('Scale' , [axes .get_yscale (), 'linear' , 'log' ]),
58
+ sep ,
59
+ ('(Re-)Generate automatic legend' , False ),
57
60
]
58
61
59
62
if has_curve :
@@ -70,8 +73,7 @@ def figure_edit(axes, parent=None):
70
73
curvelabels = sorted (linedict .keys ())
71
74
for label in curvelabels :
72
75
line = linedict [label ]
73
- curvedata = [
74
- ('Label' , label ),
76
+ curvedata = [('Label' , label ),
75
77
sep ,
76
78
(None , '<b>Line</b>' ),
77
79
('Style' , [line .get_linestyle ()] + linestyles ),
@@ -98,7 +100,8 @@ def apply_callback(data):
98
100
general , = data
99
101
100
102
# Set / General
101
- title , xmin , xmax , xlabel , xscale , ymin , ymax , ylabel , yscale = general
103
+ title , xmin , xmax , xlabel , xscale , ymin , ymax , ylabel , yscale , \
104
+ generate_legend = general
102
105
axes .set_xscale (xscale )
103
106
axes .set_yscale (yscale )
104
107
axes .set_title (title )
@@ -112,7 +115,8 @@ def apply_callback(data):
112
115
for index , curve in enumerate (curves ):
113
116
line = linedict [curvelabels [index ]]
114
117
label , linestyle , linewidth , color , \
115
- marker , markersize , markerfacecolor , markeredgecolor = curve
118
+ marker , markersize , markerfacecolor , markeredgecolor \
119
+ = curve
116
120
line .set_label (label )
117
121
line .set_linestyle (linestyle )
118
122
line .set_linewidth (linewidth )
@@ -123,11 +127,22 @@ def apply_callback(data):
123
127
line .set_markerfacecolor (markerfacecolor )
124
128
line .set_markeredgecolor (markeredgecolor )
125
129
130
+ # re-generate legend, if checkbox is checked
131
+ if generate_legend :
132
+ if axes .legend_ is not None :
133
+ old_legend = axes .get_legend ()
134
+ new_legend = axes .legend (ncol = old_legend ._ncol )
135
+ new_legend .draggable (old_legend ._draggable is not None )
136
+ else :
137
+ new_legend = axes .legend ()
138
+ new_legend .draggable (True )
139
+
126
140
# Redraw
127
141
figure = axes .get_figure ()
128
142
figure .canvas .draw ()
129
143
130
144
data = formlayout .fedit (datalist , title = "Figure options" , parent = parent ,
131
- icon = get_icon ('qt4_editor_options.svg' ), apply = apply_callback )
145
+ icon = get_icon ('qt4_editor_options.svg' ),
146
+ apply = apply_callback )
132
147
if data is not None :
133
148
apply_callback (data )
0 commit comments