Skip to content

Commit 0fa7771

Browse files
committed
Merge pull request matplotlib#2947 from anykraus/debug
Re-Generate legend, through apply_callback/Apply
2 parents a6a09c1 + 9ede5be commit 0fa7771

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

lib/matplotlib/backends/qt4_editor/figureoptions.py

+24-9
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
from matplotlib.backends.qt4_compat import QtGui
1919
from matplotlib import markers
2020

21+
2122
def get_icon(name):
2223
import matplotlib
2324
basedir = osp.join(matplotlib.rcParams['datapath'], 'images')
2425
return QtGui.QIcon(osp.join(basedir, name))
2526

26-
LINESTYLES = {
27-
'-': 'Solid',
27+
LINESTYLES = {'-': 'Solid',
2828
'--': 'Dashed',
2929
'-.': 'DashDot',
3030
':': 'Dotted',
@@ -34,9 +34,10 @@ def get_icon(name):
3434

3535
MARKERS = markers.MarkerStyle.markers
3636

37+
3738
def figure_edit(axes, parent=None):
3839
"""Edit matplotlib figure options"""
39-
sep = (None, None) # separator
40+
sep = (None, None) # separator
4041

4142
has_curve = len(axes.get_lines()) > 0
4243

@@ -53,7 +54,9 @@ def figure_edit(axes, parent=None):
5354
(None, "<b>Y-Axis</b>"),
5455
('Min', ymin), ('Max', ymax),
5556
('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),
5760
]
5861

5962
if has_curve:
@@ -70,8 +73,7 @@ def figure_edit(axes, parent=None):
7073
curvelabels = sorted(linedict.keys())
7174
for label in curvelabels:
7275
line = linedict[label]
73-
curvedata = [
74-
('Label', label),
76+
curvedata = [('Label', label),
7577
sep,
7678
(None, '<b>Line</b>'),
7779
('Style', [line.get_linestyle()] + linestyles),
@@ -98,7 +100,8 @@ def apply_callback(data):
98100
general, = data
99101

100102
# 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
102105
axes.set_xscale(xscale)
103106
axes.set_yscale(yscale)
104107
axes.set_title(title)
@@ -112,7 +115,8 @@ def apply_callback(data):
112115
for index, curve in enumerate(curves):
113116
line = linedict[curvelabels[index]]
114117
label, linestyle, linewidth, color, \
115-
marker, markersize, markerfacecolor, markeredgecolor = curve
118+
marker, markersize, markerfacecolor, markeredgecolor \
119+
= curve
116120
line.set_label(label)
117121
line.set_linestyle(linestyle)
118122
line.set_linewidth(linewidth)
@@ -123,11 +127,22 @@ def apply_callback(data):
123127
line.set_markerfacecolor(markerfacecolor)
124128
line.set_markeredgecolor(markeredgecolor)
125129

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+
126140
# Redraw
127141
figure = axes.get_figure()
128142
figure.canvas.draw()
129143

130144
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)
132147
if data is not None:
133148
apply_callback(data)

lib/matplotlib/tests/test_coding_standards.py

-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
'*/matplotlib/backends/qt4_compat.py',
135135
'*/matplotlib/backends/tkagg.py',
136136
'*/matplotlib/backends/windowing.py',
137-
'*/matplotlib/backends/qt4_editor/figureoptions.py',
138137
'*/matplotlib/backends/qt4_editor/formlayout.py',
139138
'*/matplotlib/sphinxext/ipython_console_highlighting.py',
140139
'*/matplotlib/sphinxext/ipython_directive.py',

0 commit comments

Comments
 (0)