diff --git a/lib/matplotlib/backends/qt4_editor/figureoptions.py b/lib/matplotlib/backends/qt4_editor/figureoptions.py
index f9dc2f838cbc..2e65e4fdaa7b 100644
--- a/lib/matplotlib/backends/qt4_editor/figureoptions.py
+++ b/lib/matplotlib/backends/qt4_editor/figureoptions.py
@@ -18,13 +18,13 @@
from matplotlib.backends.qt4_compat import QtGui
from matplotlib import markers
+
def get_icon(name):
import matplotlib
basedir = osp.join(matplotlib.rcParams['datapath'], 'images')
return QtGui.QIcon(osp.join(basedir, name))
-LINESTYLES = {
- '-': 'Solid',
+LINESTYLES = {'-': 'Solid',
'--': 'Dashed',
'-.': 'DashDot',
':': 'Dotted',
@@ -34,9 +34,10 @@ def get_icon(name):
MARKERS = markers.MarkerStyle.markers
+
def figure_edit(axes, parent=None):
"""Edit matplotlib figure options"""
- sep = (None, None) # separator
+ sep = (None, None) # separator
has_curve = len(axes.get_lines()) > 0
@@ -53,7 +54,9 @@ def figure_edit(axes, parent=None):
(None, "Y-Axis"),
('Min', ymin), ('Max', ymax),
('Label', axes.get_ylabel()),
- ('Scale', [axes.get_yscale(), 'linear', 'log'])
+ ('Scale', [axes.get_yscale(), 'linear', 'log']),
+ sep,
+ ('(Re-)Generate automatic legend', False),
]
if has_curve:
@@ -70,8 +73,7 @@ def figure_edit(axes, parent=None):
curvelabels = sorted(linedict.keys())
for label in curvelabels:
line = linedict[label]
- curvedata = [
- ('Label', label),
+ curvedata = [('Label', label),
sep,
(None, 'Line'),
('Style', [line.get_linestyle()] + linestyles),
@@ -98,7 +100,8 @@ def apply_callback(data):
general, = data
# Set / General
- title, xmin, xmax, xlabel, xscale, ymin, ymax, ylabel, yscale = general
+ title, xmin, xmax, xlabel, xscale, ymin, ymax, ylabel, yscale, \
+ generate_legend = general
axes.set_xscale(xscale)
axes.set_yscale(yscale)
axes.set_title(title)
@@ -112,7 +115,8 @@ def apply_callback(data):
for index, curve in enumerate(curves):
line = linedict[curvelabels[index]]
label, linestyle, linewidth, color, \
- marker, markersize, markerfacecolor, markeredgecolor = curve
+ marker, markersize, markerfacecolor, markeredgecolor \
+ = curve
line.set_label(label)
line.set_linestyle(linestyle)
line.set_linewidth(linewidth)
@@ -123,11 +127,22 @@ def apply_callback(data):
line.set_markerfacecolor(markerfacecolor)
line.set_markeredgecolor(markeredgecolor)
+ # re-generate legend, if checkbox is checked
+ if generate_legend:
+ if axes.legend_ is not None:
+ old_legend = axes.get_legend()
+ new_legend = axes.legend(ncol=old_legend._ncol)
+ new_legend.draggable(old_legend._draggable is not None)
+ else:
+ new_legend = axes.legend()
+ new_legend.draggable(True)
+
# Redraw
figure = axes.get_figure()
figure.canvas.draw()
data = formlayout.fedit(datalist, title="Figure options", parent=parent,
- icon=get_icon('qt4_editor_options.svg'), apply=apply_callback)
+ icon=get_icon('qt4_editor_options.svg'),
+ apply=apply_callback)
if data is not None:
apply_callback(data)
diff --git a/lib/matplotlib/tests/test_coding_standards.py b/lib/matplotlib/tests/test_coding_standards.py
index ac690c50effd..45d1be620b5d 100644
--- a/lib/matplotlib/tests/test_coding_standards.py
+++ b/lib/matplotlib/tests/test_coding_standards.py
@@ -134,7 +134,6 @@
'*/matplotlib/backends/qt4_compat.py',
'*/matplotlib/backends/tkagg.py',
'*/matplotlib/backends/windowing.py',
- '*/matplotlib/backends/qt4_editor/figureoptions.py',
'*/matplotlib/backends/qt4_editor/formlayout.py',
'*/matplotlib/sphinxext/ipython_console_highlighting.py',
'*/matplotlib/sphinxext/ipython_directive.py',